# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('name_of_your_dataset.csv')
X = dataset.iloc[:, [2, 3, 4]].values
# syntax : dataset.iloc[nrows, ncols].values
# ':' depicts all the rows in the dataset
# ncols takes 3rd, 4th and 5th column of the dataset into X
# Change that to your respective columns
y = dataset.iloc[:, 5].values
# Splitting the dataset into the Training set and Test set
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# Fitting SVM to the Training set
# You can use any classifier to predict
# This is just a sample program
from sklearn.svm import SVC
classifier = SVC(kernel = 'linear', random_state = 0)
classifier.fit(X_train, y_train)
# Predicting the Test set results
y_pred = classifier.predict(X_test)
这是一个6列n行数据集的示例分类器
上面是
对于分类数据的编码,需要创建
dummy variables
请记住,
dummy variables
必须比列中的categorical variables
个数少1。否则,程序可能会导致dummy variable trap
这是一列的
encoding
分类特性的代码。请将这段代码放在splitting of datasets
前面您可以通过将
0's
更改为各自的列来对其他列执行相同的操作, 或者使用for
循环相关问题 更多 >
编程相关推荐