python 多分类预测_多类分类与概率预测

import pandas as pd

import numpy

from sklearn import cross_validation

from sklearn.naive_bayes import GaussianNB

fi = "df.csv"

# Open the file for reading and read in data

file_handler = open(fi, "r")

data = pd.read_csv(file_handler, sep=",")

file_handler.close()

# split the data into training and test data

train, test = cross_validation.train_test_split(data,test_size=0.6, random_state=0)

# initialise Gaussian Naive Bayes

naive_b = GaussianNB()

train_features = train.ix[:,0:127]

train_label = train.iloc[:,127]

test_features = test.ix[:,0:127]

test_label = test.iloc[:,127]

naive_b.fit(train_features, train_label)

test_data = pd.concat([test_features, test_label], axis=1)

test_data["p_malw"] = naive_b.predict_proba(test_features)

print "test_data\n",test_data["p_malw"]

print "Accuracy:", naive_b.score(test_features,test_label)

我编写了这段代码来接受来自一个包含128列的csv文件的输入,其中127列是特性,第128列是类标签。在

我想预测样本属于每个类别(有5个类别(1-5))的概率,并将其打印到矩阵的for中,并根据预测确定样本的类别。predict_proba()没有给出所需的输出。请建议所需的更改。在

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值