Skip to content

Commit

Permalink
# -*- coding: utf-8 -*-
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss authored Jan 4, 2018
1 parent 202ff3b commit e23cab5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions LogisticRegression/LogisticRegression_scikit-learn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.cross_validation import train_test_split
Expand All @@ -8,32 +10,32 @@ def logisticRegression():
X = data[:,0:-1]
y = data[:,-1]

# ����Ϊѵ�����Ͳ��Լ�
# 划分为训练集和测试集
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.2)

# ��һ��
# 归一化
scaler = StandardScaler()
scaler.fit(x_train)
x_train = scaler.fit_transform(x_train)
x_test = scaler.fit_transform(x_test)

#�߼��ع�
# 逻辑回归
model = LogisticRegression()
model.fit(x_train,y_train)

# Ԥ��
# 预测
predict = model.predict(x_test)
right = sum(predict == y_test)

predict = np.hstack((predict.reshape(-1,1),y_test.reshape(-1,1))) # ��Ԥ��ֵ����ʵֵ����һ�飬�ù۲�
predict = np.hstack((predict.reshape(-1,1),y_test.reshape(-1,1))) # 将预测值和真实值放在一块,好观察
print(predict)
print('���Լ�׼ȷ�ʣ�%f%%'%(right*100.0/predict.shape[0])) #�����ڲ��Լ��ϵ�׼ȷ��
print('测试集准确率:%f%%'%(right*100.0/predict.shape[0])) # 计算在测试集上的准确度

# ����txt��csv�ļ�
# 加载txt和csv文件
def loadtxtAndcsv_data(fileName,split,dataType):
return np.loadtxt(fileName,delimiter=split,dtype=dataType)

# ����npy�ļ�
# 加载npy文件
def loadnpy_data(fileName):
return np.load(fileName)

Expand Down

0 comments on commit e23cab5

Please sign in to comment.