本文整理匯總了Python中Dataset.Dataset.getTrainAndTestSets方法的典型用法代碼示例。如果您正苦於以下問題:Python Dataset.getTrainAndTestSets方法的具體用法?Python Dataset.getTrainAndTestSets怎麽用?Python Dataset.getTrainAndTestSets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.getTrainAndTestSets方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Rivera
# 需要導入模塊: from Dataset import Dataset [as 別名]
# 或者: from Dataset.Dataset import getTrainAndTestSets [as 別名]
#!/usr/bin/python
# CIS 521 Homework 7: Learning Machine Learning
# Cory Rivera (rcor) and Sam Panzer (panzers)
from numpy import *
from Dataset import Dataset
d = Dataset("comp.sys.ibm.pc.hardware.txt",
"rec.sport.baseball.txt", cutoff=10)
#d = Dataset("comp.sys.mac.hardware.txt", "comp.sys.ibm.pc.hardware.txt", cutoff=2000)
(Xtrain, Ytrain, Xtest, Ytest) = d.getTrainAndTestSets(0.8, seed=1)
wordlist = d.getWordList()
def trainNaiveBayes(X, Y):
# First, count frequencies given the category
# Each row is a post, and each column is a word
# To count the number of words from every post, sum up the values from each
# column for a given category
# Flattens Y so that it is easier to iterate over
yFlat = Y.flatten()
yPos = yFlat == 1
yNeg = yFlat == -1
# X.shape[1] returns number of columns for a given matrix
numColumns = X.shape[1]
# Indexing with a boolean array like yOne only checks indices that are True