分类人、狗、猫,‘class’是0,代表是人;1代表是猫猫;2代表是狗狗;
特征是 4个数据特征,暂且不知特征怎么来的,反正是csv文件,150个样本。
遇到很多困难。
1、加载数据、
为了加载数据并很好地进行格式化,我们将使用两个非常有用的包,即 Pandas 和 Numpy。 你可以在这里阅读文档:
%matplotlib inline
# Importing pandas and numpy
import pandas as pd
import numpy as np
from IPython.display import display
# present all plots in the notebook
# Reading the csv file into a pandas DataFrame
dataset = pd.read_csv('data.csv')
#random all the rows in dataset
dataset = dataset.sample(frac=1)
# print data shortcut
dataset[:10]
2、数据分析 - 绘制数据,可视化的数据分析
首先让我们对数据进行绘图,看看他们互相之间的关系是什么。首先来看试一下feature1和feature2
# Importing matplotlib
import matplotlib.pyplot as plt
# Function to help us plot
def plot_points(dataset):
X = np.array(dataset[["feature1","feature2"]])
y = np.array(dataset["class"])
people = X[np.argwhere(y==0)]
cat = X[np.argwhere(y==1)]
dog = X[np.argwhere(y==2)]
plt.scatter([s[0][0] for s in people], [s[0][1] for s in people], s = 25, color = 'red', edgecolor = 'k')
plt.scatter([s[0][0] for s in cat], [s[0][1] for s in cat], s = 25, color = 'cyan', edgecolor = 'k')
plt.scatter([s[0][0] for s in dog], [s[0][1] for s in dog], s = 25, color = 'yellow', edgecolor = 'k')
plt.xlabel('Feature_1')
plt.ylabel('Feature_2')
# Plotting the points
plot_points(dataset)
plt.show()
图上红色是人,青色是小猫,黄色是小狗。 粗略来说,这两个feature并没有很好地分离图像小狗,小猫和人。 也许将另两个features考虑进来会有帮助? 接下来我们将绘制一组图,用seaborn的pairplot函数来试试吧!