<jupyter_start><jupyter_text>MinMaxScaler<jupyter_code>from sklearn.preprocessing import MinMaxScaler
mMscaler = MinMaxScaler()
# mMscaler.fit(data)
# mMscaled_data = mMscaler.transform(data)
mMscaled_data = mMscaler.fit_transform(data)
mMscaled_data = pd.DataFrame(mMscaled_data, columns=data.columns)
mMscaled_data.head()<jupyter_output><empty_output><jupyter_text>Standard Scaling<jupyter_code>from sklearn.preprocessing import StandardScaler
sdscaler = StandardScaler()
sdscaled_data = sdscaler.fit_transform(data)
sdscaled_data = pd.DataFrame(sdscaled_data, columns=data.columns)
sdscaled_data.head()<jupyter_output><empty_output><jupyter_text>Sampling: SMOTE(Synthetic Minority Oversampling Technique)<jupyter_code>from imblearn.over_sampling import SMOTE
smote = SMOTE(k_neighbors=5)
smoted_data, smoted_label = smote.fit_resample(data, label)
print('원본 데이터의 클래스 비율 \n{}'.format(pd.get_dummies(label).sum()))
print('\nSMOTE 결과\n{}'.format(pd.get_dummies(smoted_label).sum()))
smoted_label
for i in range(len(smoted_label)):
    if smoted_label[i]=='F':
        smoted_label[i]=0
    elif smoted_label[i]=='I':
        smoted_label[i]=1
    else:
        smoted_label[i]=2
smoted_label
fig = plt.Figure(figsize=(12,6))
plt.scatter(smoted_data[:,0], smoted_data[:,1], c=smoted_label, linewidth=1, edgecolor='black')
plt.show()<jupyter_output><empty_output><jupyter_text>PCA<jupyter_code>from sklearn.datasets import load_digits
digits = load_digits()
d_data = digits.data
d_label = digits.target
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
new_d_data = pca.fit_transform(d_data)
plt.scatter(new_d_data[:,0], new_d_data[:,1], c=d_label, linewidths=1, edgecolors='black')
plt.show()<jupyter_output><empty_output><jupyter_text>Label Encoding<jupyter_code>from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
encoded_label = le.fit_transform(label)<jupyter_output><empty_output><jupyter_text>OneHot Encoding<jupyter_code>from sklearn.preprocessing import OneHotEncoder
ohe = OneHotEncoder()
oh_label = ohe.fit_transform(label.values.reshape(-1, 1))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1249408424041647, 'fraction_numerical': 0.007572172266919072, 'mean_word_length': 9.262135922330097, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '658572', 'license': 'MIT', 'n_tokens_mistral': 842, 'n_tokens_neox': 828, 'n_words': 109, 'path': 'Data_Preprocessing.ipynb', 'repo_name': 'sseungyong/sklearn_basic', 'size': '2113'}