In [46]:
# 导入头文件
import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC

import matplotlib.pyplot as plt

In [47]:
data = pd.read_csv('data.csv')
np.array(data['y'])


Out[47]:
array([0., 1., 1., 1., 0., 0., 1., 0., 1., 1., 1., 1., 0., 1., 0., 0., 1.,
       0., 1., 1., 1., 0., 1., 0., 0., 0., 0., 0., 1., 0., 1., 1., 1., 1.,
       1., 1., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1.,
       0., 0., 1., 1., 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 1., 0., 0.,
       0., 1., 0., 0., 1., 1., 1., 0., 0., 1., 0., 1., 1., 1., 0., 1., 1.,
       1., 1., 0., 0., 1., 0., 0., 0., 1., 1., 0., 0., 1., 1., 1.])

In [48]:
# 分解数据中的
X = np.array(data[['x1', 'x2']])
y = np.array(data['y'])

In [49]:
plt.scatter(X[:,0],X[:,1],c=y)


Out[49]:
<matplotlib.collections.PathCollection at 0x1a1814edd8>

In [50]:
# Logistic Regression Classifier
lg_classifier = LogisticRegression()
lg_classifier.fit(X,y)


/Users/weixu/AI/tool/anaconda3/envs/py3/lib/python3.6/site-packages/sklearn/linear_model/logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
Out[50]:
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
          intercept_scaling=1, max_iter=100, multi_class='warn',
          n_jobs=None, penalty='l2', random_state=None, solver='warn',
          tol=0.0001, verbose=0, warm_start=False)

In [51]:
y_p = classifier.predict(X)

In [54]:
plt.scatter(X[:,0],X[:,1],c=y_p)


Out[54]:
<matplotlib.collections.PathCollection at 0x11065f390>

In [55]:
Dt_classifier = DecisionTreeClassifier()
Dt_classifier.fit(X, y)


Out[55]:
DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,
            max_features=None, max_leaf_nodes=None,
            min_impurity_decrease=0.0, min_impurity_split=None,
            min_samples_leaf=1, min_samples_split=2,
            min_weight_fraction_leaf=0.0, presort=False, random_state=None,
            splitter='best')

In [56]:
y_Dp = classifier.predict(X)
plt.scatter(X[:,0],X[:,1],c=y_Dp)


Out[56]:
<matplotlib.collections.PathCollection at 0x1a1887a5c0>

In [57]:
svc_classifier = SVC()
svc_classifier.fit(X, y)


/Users/weixu/AI/tool/anaconda3/envs/py3/lib/python3.6/site-packages/sklearn/svm/base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.
  "avoid this warning.", FutureWarning)
Out[57]:
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
  decision_function_shape='ovr', degree=3, gamma='auto_deprecated',
  kernel='rbf', max_iter=-1, probability=False, random_state=None,
  shrinking=True, tol=0.001, verbose=False)

In [58]:
y_sp = svc_classifier.predict(X)
plt.scatter(X[:,0],X[:,1],c=y_p)


Out[58]:
<matplotlib.collections.PathCollection at 0x1a15568a90>

In [ ]: