当前位置: 首页>>代码示例>>Python>>正文


Python Perceptron.fit_transform方法代码示例

本文整理汇总了Python中sklearn.linear_model.Perceptron.fit_transform方法的典型用法代码示例。如果您正苦于以下问题:Python Perceptron.fit_transform方法的具体用法?Python Perceptron.fit_transform怎么用?Python Perceptron.fit_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.linear_model.Perceptron的用法示例。


在下文中一共展示了Perceptron.fit_transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fetch_20newsgroups

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import fit_transform [as 别名]
plt.xlabel('Proportion of the day spent sleeping')
plt.ylabel('Proportion of the day spent being grumpy')
plt.title('Kittens and Adult Cats')
plt.show()

#Perceptron 
categories = ['rec.sport.hockey', 'rec.sport.baseball', 'rec.autos']
newsgroups_train = fetch_20newsgroups(subset='train', categories=categories, remove=('headers', 'footers', 'quotes'))
newsgroups_test = fetch_20newsgroups(subset='test', categories=categories, remove=('headers', 'footers', 'quotes'))

vectorizer = TfidfVectorizer()
X_train = vectorizer.fit_transform(newsgroups_train.data)
X_test = vectorizer.transform(newsgroups_test.data)

classifier = Perceptron(n_iter=100, eta0=0.1)
classifier.fit_transform(X_train, newsgroups_train.target)
predictions = classifier.predict(X_test)
print classification_report(newsgroups_test.target, predictions)
"""
Output seen
             precision    recall  f1-score   support

          0       0.89      0.87      0.88       396
          1       0.87      0.78      0.82       397
          2       0.79      0.88      0.83       399

avg / total       0.85      0.85      0.85      1192
"""

#plot the output
import matplotlib
开发者ID:AgileHacker,项目名称:Practical-Machine-Learning,代码行数:33,代码来源:perceptron.py

示例2: len

# 需要导入模块: from sklearn.linear_model import Perceptron [as 别名]
# 或者: from sklearn.linear_model.Perceptron import fit_transform [as 别名]
#df = df._get_numeric_data()

#msk = np.random.rand(len(df)) < 0.8
train = df
train_target = train['Survived']
train = train.drop('Survived',axis=1)
#print train
test = df_test
#test_target = test['Survived']
#test = test.drop('Survived',axis=1)

print len(train)
print len(test)
#print newsgroups_train.filenames

#print newsgroups_test.filenames.shape

#print vectorizer
#print X_train

classifier = Perceptron(n_iter=5000, eta0=0.3)
classifier.fit_transform(train, train_target )
predictions = classifier.predict(test)
#print predictions
#print classification_report(test_target, predictions)
print predictions
np.savetxt('test_final.csv',predictions)

#cm = confusion_matrix(test_target,predictions)
#print cm
#print classifier.score(train,train_target)
开发者ID:deepitapai,项目名称:Titanic,代码行数:33,代码来源:titanic_script_1.py


注:本文中的sklearn.linear_model.Perceptron.fit_transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。