ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • learning
    Cording/Python 2021. 2. 13. 01:24

    Scikit-Learn 라이브러리

     

    import pandas ad pd

    df = pd.read_csv(C:/myCode/data/basketball_stat.csv')

    data_df = df[0:100]

    data_df.head()

     

    from sklearn.model_selection import train_test_split

     

    # 학습데이터 80%, 테스트데이터 20%로 분리

    train, test = train_test_split(data_df, best_size=0.2)

    train.shape

     

    # 일부만 가져옴.

    train_data_df = train[['3P',"BLK',"TRB']]

    train_label_df = train[["Pos']]

    tarin_data_df.head()

     

    # KNN 라이브 추가

    from sklearn.neighbors import KNeighborsClassfier

     

    knn = KNeighborsClassifier(n_neighbors=3)

    knn.fit(train_data, train_label)

     

    pred_knn = knn.predict(test_data)

    pred_knn

     

    from sklearn import metrics

     

    ac_score = metrics.accuracy_score(test_label, pred_knn)

    print('accuracy:', ac_score)

     

    # 모델 예측 정확도 확인

    comparison = pd.DataFrame({'prediction':pred_knn, 'ground_truth':test_label})

    comparison

     

    # svm 모델 학습

    from sklearn import svm

    clf = svm.SVC(C = 1, gamma = 0.1) # gamma = 0.1은 가정

    clif.fit(train_data, train_label)

     

    # 테스트 데이터로 예측

    pred_svm = clf.predict(test_data)

    pred.svm

     

    # 모델 예측 정확도 확인

    from sklearn import metrics

     

    ac_score = metrics.accuracy.score(test_label, pred_svm)

    print('accuracy:', ac_score)

     

    * Deep Learning

     

    import tensorflow as tf

    import pandas as pd

    import numpy as np

     

    df = pd.read_csv()

    Data_set = df.values

    Data_set

     

    from sklearn.model_selection import train_test_split

     

    # 데아터셋에서 학습데이터, 테스트데이터를 분리

    train, test = train_test_split(Data_set, test_size = 0.2)

     

    # 속성과 클래스 분리

    X_train = train[:, 0:17]

    Y_train = train[:, 17]

    X_train

     

    from keras.models import Sequential

    from keras.layers import Dense

     

    model = Sequential()

     

    model.add(Dense(30, input dim=17, activation='relu'))

    model.add(dense(1, activation='sigmoid'))

     

    model.compile(loss='mean_squared_error', optimizer = 'adam', metrics=['accuracy'])

     

    'Cording > Python' 카테고리의 다른 글

    for, 문자열  (0) 2021.02.05
    machine learning  (0) 2021.02.01
    전처리  (0) 2021.01.28
    Graph  (0) 2021.01.22
    jupyter-data visualization  (0) 2021.01.21

    댓글

Designed by Tistory.