【问题标题】:how to extract the features and labels from csv file to use them in the classifier fitting?如何从 csv 文件中提取特征和标签以在分类器拟合中使用它们?
【发布时间】:2018-02-12 03:50:48
【问题描述】:

the photo showing my dataset.csv

上面的照片显示了我的 .csv 数据。我使用基本代码将数据拆分为训练和测试集 80/20,如下代码所示。 问题是我不知道如何将数据适合分类器(clf.fit(features,labels))我有三个特征(pdb,pds和pdsh)和三个标签(大,紧凑和小)如何提取它们来自 csv 文件?

import pandas as pd
import numpy as np

df = pd.read_csv('pd.csv')
df['split'] = np.random.randn(df.shape[0], 1)

splt = np.random.rand(len(df)) <= 0.8

train = df[splt]
test = df[~splt]

#The svm classifier 
from sklearn.metrics import accuracy_score
from sklearn import svm
clf = svm.SVC()
clf.fit(features, labels)
result = clf.predict(featuresT)
print(accuracy_score(TestLabels, result)*100)

任何建议将不胜感激 谢谢你

【问题讨论】:

    标签: python-3.x machine-learning classification


    【解决方案1】:

    请在互联网上搜索您的问题,因为有可用的解决方案。我还在写。

    首先要将标签转换为数字 0、1、2。

    当您使用 pandas 时,您可以通过 label = df['Name'] 提取标签。但是现在您必须从训练和测试数据集中删除目标列。

    要删除列使用:

    train = train.drop(['Name'],axis=1)

    test = test.drop(['Name'],axis=1)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      • 2017-02-13
      • 2019-06-30
      • 2021-06-01
      • 1970-01-01
      • 2014-08-26
      • 2011-06-28
      相关资源
      最近更新 更多