【发布时间】:2017-09-03 05:35:44
【问题描述】:
我有一些有趣的用户数据。它提供了有关用户被要求执行的某些任务的及时性的一些信息。我试图找出,如果late - 它告诉我用户是否准时 (0)、有点晚 (1) 或相当晚 (2) - 是可预测/可解释的。我从提供交通信号灯信息的列中生成late(绿色=未迟到,红色=超级迟到)。
这是我的工作:
#imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import preprocessing
from sklearn import svm
import sklearn.metrics as sm
#load user data
df = pd.read_csv('April.csv', error_bad_lines=False, encoding='iso8859_15', delimiter=';')
#convert objects to datetime data types
cols = ['Planned Start', 'Actual Start', 'Planned End', 'Actual End']
df = df[cols].apply(
pd.to_datetime, dayfirst=True, errors='ignore'
).join(df.drop(cols, 1))
#convert datetime to numeric data types
cols = ['Planned Start', 'Actual Start', 'Planned End', 'Actual End']
df = df[cols].apply(
pd.to_numeric, errors='ignore'
).join(df.drop(cols, 1))
#add likert scale for green, yellow and red traffic lights
df['late'] = 0
df.ix[df['End Time Traffic Light'].isin(['Yellow']), 'late'] = 1
df.ix[df['End Time Traffic Light'].isin(['Red']), 'late'] = 2
#Supervised Learning
#X and y arrays
# X = np.array(df.drop(['late'], axis=1))
X = df[['Planned Start', 'Actual Start', 'Planned End', 'Actual End', 'Measure Package', 'Measure' , 'Responsible User']].as_matrix()
y = np.array(df['late'])
#preprocessing the data
X = preprocessing.scale(X)
#Supper Vector Machine
clf = svm.SVC(decision_function_shape='ovo')
clf.fit(X, y)
print(clf.score(X, y))
我现在正在尝试了解如何绘制决策边界。我的目标是使用 Actual End 和 Planned End 绘制 2 路散点图。自然地,我检查了文档(参见例如here)。但我无法绕过它。这是如何工作的?
【问题讨论】:
-
一方面,您链接的文档页面中的决策边界图基于两个数字列(sepal.width,sepal.length)绘制预测和真实类。您的 X 中有很多列。您希望将哪两个用于决策边界图中的 x、y 轴?如果您有第三个分类变量,则可以通过为(第三个)分类变量的每个级别绘制前两个变量的单独决策边界图,将其包含在可视化中。
-
抱歉,错过了什么。我想绘制一个基于
Planned End和Actual End的二维散点图。我将编辑问题!谢谢!
标签: python-3.x plot scikit-learn supervised-learning