本文整理汇总了Python中sklearn.multiclass.OneVsOneClassifier.to_csv方法的典型用法代码示例。如果您正苦于以下问题:Python OneVsOneClassifier.to_csv方法的具体用法?Python OneVsOneClassifier.to_csv怎么用?Python OneVsOneClassifier.to_csv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.multiclass.OneVsOneClassifier
的用法示例。
在下文中一共展示了OneVsOneClassifier.to_csv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CountVectorizer
# 需要导入模块: from sklearn.multiclass import OneVsOneClassifier [as 别名]
# 或者: from sklearn.multiclass.OneVsOneClassifier import to_csv [as 别名]
from sklearn import cross_validation
from sklearn.ensemble import RandomForestClassifier
import numpy as np
##With Bag of words and One-vs-all and One-vs-One
train=pd.read_csv("train.csv")
test=pd.read_csv("test.csv")
vectorizer = CountVectorizer(analyzer = "word",max_features=5000)
train_data_features = vectorizer.fit_transform(train["Summary"])
test_data_features=vectorizer.transform(test["Summary"])
resultWithOneVsRest = OneVsRestClassifier(LinearSVC(random_state=0)).fit(train_data_features, train["Topic"]).predict(test_data_features)
resultWithOneVsOne= OneVsOneClassifier(LinearSVC(random_state=0)).fit(train_data_features, train["Topic"]).predict(test_data_features)
outputWithOneVsRest = pd.DataFrame( data={"record_id":test["RecordID"], "topic_id":resultWithOneVsRest} )
outputWithOneVsRest.to_csv( "Task1_outputWithOneVsRest.tsv", index=False, quoting=3 , sep="\t")
resultWithOneVsOne = pd.DataFrame( data={"record_id":test["RecordID"], "topic_id":resultWithOneVsOne} )
resultWithOneVsOne.to_csv( "Task1_resultWithOneVsOne.tsv", index=False, quoting=3, sep="\t")
##with TF-idf with One-vs-all and One-vs-One
tf_idf=TfidfVectorizer(max_features=5000)
train_data_features = tf_idf.fit_transform(train["Summary"])
test_data_features=tf_idf.transform(test["Summary"])
resultWithOneVsRestModel = OneVsRestClassifier(LinearSVC(random_state=0)).fit(train_data_features, train["Topic"])
print np.mean(cross_validation.cross_val_score(resultWithOneVsRestModel,train_data_features,train["Topic"],cv=20))
resultWithOneVsRest_tfidf = resultWithOneVsRestModel.predict(test_data_features)
op=pd.DataFrame(data={"record_id":test["RecordID"],"topic_id":resultWithOneVsRest_tfidf})
op.to_csv("Task-1_With_TfIdf.tsv",index=False,quoting=3,sep="\t");