¡¶È˹¤ÖÇÄÜÓë»úÆ÷ѧϰ¡·
ʵÑ鱨¸æ
Ä꼶__xxxx__________ רҵ________xxxxxx__________ ѧºÅ____________631507xxxx___________ ÐÕÃû_____________gllh________________
ÈÕÆÚ___________2024-5-25__
ʵÑéÆßÉñ¾ÍøÂçËã·¨
Ò»¡¢ÊµÑéÄ¿µÄ
1¡¢ÒªÇóÕÆÎÕÉñ¾ÍøÂçËã·¨µÄ»ù±¾ÔÀí¡¢Á˽âÉñ¾ÍøÂçËã·¨µÄÖ´Ðйý³Ì¡£ 2¡¢ÔÚ´Ë»ù´¡ÉÏ£¬ÀûÓöà²ãÉñ¾ÍøÂçËã·¨¶Ô¸ø¶¨Ñù±¾Êý¾ÝʵÏÖ·ÖÀà¡£
ʵÑéÀàÐÍ£ºÑéÖ¤ÐÔ ¼Æ»®¿Î¼ä£º2ѧʱ
¶þ¡¢ÊµÑéÄÚÈÝ
1¡¢Á˽âÉñ¾ÍøÂçËã·¨µÄÍøÂç½á¹¹ 2¡¢Á˽âÉñ¾ÍøÂçµÄ·´Ïò´«²¥¹ý³Ì£»
3¡¢¶Ô¸ø¶¨Ñù±¾Êý¾ÝÑ¡ÔñºÏÊʵÄÍøÂç²ãÊýºÍÉñ¾Ôª¸öÊýʵÏÖ·ÖÀà¹ý³Ì£»
Èý¡¢ÊµÑé²½Öè
1¡¢Êý¾Ý¼¯¶ÁÈë
±¾ÊµÑéÑ¡ÓÃÄÐÅ®ÉúÉí¸ßÌåÖØÊý¾Ý¼¯£º
ÔÚÊý¾Ý¼¯Öн«Å®Éú»®·ÖΪ1£¬ÄÐÉú»®·ÖΪ2£¬Èç½ØͼËùʾ
sex = pd.read_csv('fafa.csv', names = [\sex.head()
sex.describe().transpose() sex.shape
2¡¢Êý¾ÝÔ¤´¦Àí£¬¸ù¾ÝÐèÒª½øÐбê×¼»¯£¬¹éÒ»»¯´¦Àí X = sex.drop('devided',axis=1) y = sex['devided']
3¡¢½«Êý¾Ý¼¯»®·ÖΪѵÁ·¼¯Óë²âÊÔ¼¯
X_train, X_test, y_train, y_test = train_test_split(X, y) scaler = StandardScaler() scaler.fit(X_train) 4¡¢ÀûÓÃѵÁ·Êý¾Ý¹¹½¨Ä£ÐÍ
mlp = MLPClassifier(hidden_layer_sizes=(20,51,51),max_iter=5000) mlp.fit(X_train,y_train) 5¡¢ÓòâÊÔÊý¾ÝÆÀ¼ÛÄ£Ð͵ÄÐÔÄÜ
predictions = mlp.predict(X_test)
×Ü´úÂ룺
import pandas as pd
from sklearn.preprocessing import StandardScaler from sklearn.neural_network import MLPClassifier from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report,confusion_matrix
def readdata(data):
sex = pd.read_csv(data, names = [\ sex.head()
sex.describe().transpose()
sex.shape
X = sex.drop('devided',axis=1) y = sex['devided']
X_train, X_test, y_train, y_test = train_test_split(X, y) scaler = StandardScaler() scaler.fit(X_train)
X_train = scaler.transform(X_train) X_test = scaler.transform(X_test)
mlp = MLPClassifier(hidden_layer_sizes=(55, 55, 55),max_iter=5000) mlp.fit(X_train,y_train)
predictions = mlp.predict(X_test)
print(confusion_matrix(y_test,predictions)) print(classification_report(y_test,predictions))
print(len(mlp.coefs_)) print(len(mlp.coefs_[0])) print(len(mlp.intercepts_[0]))
if __name__ =='__main__': file='fafa.csv' readdata(file)
ʵÑé½á¹û£º
ËÄ¡¢ÊµÑé½á¹û·ÖÎö ʵÑéµÃ³öÈçϽá¹û£º
ÔÚʵÑéÖн«×î´óµü´ú´ÎÊýÉèΪ5000£¬
½ÓÏÂÀ´ÎÒÃÇ´´½¨Ò»¸öÄ£Ð͵ÄʵÀý£¬¿ÉÒÔ×Ô¶¨ÒåºÜ¶à²ÎÊý£¬Ö»¶¨Òå hidden_layer_sizes ²ÎÊý¡£´Ë²ÎÊý´«ÈëµÄÊÇÒ»¸öÔª×飬±íʾ¼Æ»®ÔÚÿ¸ö²ãµÄÉñ¾ÔªÊýÁ¿£¬ÆäÖÐÔª×éÖеĵÚ55¸öÔªËرíʾ MLP Ä£Ð͵Ú55²ãÖеÄÉñ¾ÔªÊýÁ¿¡£Óкܶà²ÎÊý¿É¹©Ñ¡Ôñ£¬µ«ÊÇΪÁ˼òµ¥Æð¼û£¬ÎÒÃǽ«Ñ¡Ôñ¾ßÓÐÏàͬÊýÁ¿Éñ¾ÔªµÄ2²ãÉñ¾ÍøÂ磬ÿ²ãµÄÉñ¾ÔªÊýÁ¿ÓëÊý¾ÝµÄÌØÕ÷ÊýÏàͬ£¨55£©£¬²¢½«×î´óµü´ú´ÎÊýÉèÖÃΪ 5000´Î¡£ ¼´£º
mlp = MLPClassifier(hidden_layer_sizes=(55,55,55),max_iter=5000)
[[30 10] [ 2 40]]
precision recall f1-score support