빅데이터 분석기사 실기 시험 Tip

김신영·2024년 6월 20일
0
post-thumbnail
post-custom-banner
import pandas as pd
import numpy as np
import sklearn

# LabelEncoder
from sklearn.preprocessing import LabelEncoder
# from sklearn.preprocessing import OneHotEncoder

# Scaler
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import MinMaxScaler

# train test data setting
from sklearn.model_selection import train_test_split

# model performance test
from sklearn.metrics import accuracy_score
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.metrics import f1_score
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix

# PCA
from sklearn.decomposition import PCA

# Classifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC

# Regressor
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.ensemble import RandomForestRegressor

# Cluster
from sklearn.cluster import KMeans

# Assiciation Rule
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules

# Descriptive Statistics
import matplotlib.pyplot as plt
import seaborn as sns
import scipy
import scipy.stats as stats

# Linear Regression (OLS)
import statsmodels
import statsmodels.formula.api as smf
import statsmodels.api as sm
import statsmodels.stats.api as sms

# Association Rule
import mlxtend
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
from mlxtend.preprocessing import TransactionEncoder

# Hypothesis Test
from scipy.stats import ttest_1samp
from scipy.stats import ttest_ind
from scipy.stats import ttest_rel

from scipy.stats import chi2_contingency
from scipy.stats import chisquare

from scipy.stats import pearsonr
from scipy.stats import spearmanr
from scipy.stats import kendalltau

from scipy.stats import spearmanr

from scipy.stats import shapiro
from scipy.stats import normaltest
from scipy.stats import kstest

from scipy.stats import mannwhitneyu

# Util
import pkgutil
import inspect

def get_object_type(obj):
    if inspect.ismodule(obj):
        return "module"
    elif inspect.isclass(obj):
        return "class"
    elif inspect.isfunction(obj):
        return "function"
    elif inspect.ismethod(obj):
        return "method"
    else:
        return "unknown"

def list_all_classes(module):
    return [(name, get_object_type(obj)) for name, obj in inspect.getmembers(module) if inspect.isclass(obj) and not name.startswith("_")]
    
def list_all_functions(module):
    return [(name, get_object_type(obj)) for name, obj in inspect.getmembers(module) if inspect.isfunction(obj) and not name.startswith("_")]

def list_all_modules(module):
    return [(name, get_object_type(obj)) for name, obj in inspect.getmembers(module) if inspect.ismodule(obj) and not name.startswith("_")]

def list_all(module):
    return [(name, get_object_type(obj)) for name, obj in inspect.getmembers(module) if not name.startswith("_")]

def hypothesis_test(p_value, alpha=0.05):
    if (p_value <= alpha):
        print(f"p_value = {p_value} <= {alpha}, null hypothesis is rejected.")
    else:
        print(f"p_value = {p_value} > {alpha}, null hypothesis is accepted.")
        
def predict(y_test, y_pred, score_func, **kwargs):
    print(f"{score_func.__name__} = {score_func(y_test, y_pred, **kwargs)}")
profile
Hello velog!
post-custom-banner

0개의 댓글