當前位置: 首頁>>代碼示例>>Python>>正文


Python Dataset.getTrainAndTestSets方法代碼示例

本文整理匯總了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
開發者ID:kshi,項目名稱:cis521-Projects,代碼行數:33,代碼來源:hw7.py


注:本文中的Dataset.Dataset.getTrainAndTestSets方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。