赞
踩
import numpy as np
import matplotlib.pyplot as plt
from testCases import *
import sklearn
import sklearn.datasets
import sklearn.linear_model
from planar_utils import plot_decision_boundary, sigmoid, load_planar_dataset, load_extra_datasets
np.random.seed(1) # set a seed so that the results are consistent
X
and Y
.X, Y = load_planar_dataset()
plt.scatter(X[0, :], X[1, :], c=np.squeeze(Y), s=40, cmap=plt.cm.Spectral)
plt.show()
shape
of the variables X
and Y
?shape_X = X.shape#X.shape是2*400
shape_Y = Y.shape#Y.shape是1*400
m = shape_X[1] # training set size
print(‘The shape of X is: ’ + str(shape_X))#(2,400)
print(‘The shape of Y is: ’ + str(shape_Y))#(1,400)
print(‘I have m = %d training examples!’ % (m))#m=400
clf = sklearn.linear_model.LogisticRegressionCV()
clf.fit(X.T, Y.T)
plot_decision_boundary(lambda x: clf.predict(x), X, Y)
plt.title(“Logistic Regression”)
LR_predictions = clf.predict(X.T)#所有预测的结果400个行向量
print(‘Accuracy of logistic regression: %d ’ % float(
(np.dot(Y, LR_predictions) + np.dot(1 - Y, 1 - LR_predictions)) / float(Y.size) * 100) +
‘% ’ + “(percentage of correctly labelled datapoints)”)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。