ML之LoR&SGD:基于LoR(逻辑回归)、SGD梯度下降算法对乳腺癌肿瘤(10+1)进行二分类预测(良/恶性)
ML之LoR&SGD:基于LoR(逻辑回归)、SGD梯度下降算法对乳腺癌肿瘤(10+1)进行二分类预测(良/恶性)
输出结果
breast-cancer size (683, 11)
训练集情况
2 344
4 168
Name: Class, dtype: int64
测试集情况
2 100
4 71
Name: Class, dtype: int64
设计思路
核心代码
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(data[column_names[1:10]], data[column_names[10]], test_size=0.25, random_state=33)
ss = StandardScaler()
X_train = ss.fit_transform(X_train)
X_test = ss.transform(X_test)
lr = LogisticRegression()
sgdc = SGDClassifier()
lr.fit(X_train, y_train)
lr_y_predict = lr.predict(X_test)
sgdc.fit(X_train, y_train)
sgdc_y_predict = sgdc.predict(X_test)
lr.score(X_test, y_test))
sgdc.score(X_test, y_test))
赞 (0)