1 回答

TA貢獻1796條經(jīng)驗 獲得超4個贊
golearn
->knn
實現(xiàn) k 最近鄰算法。它是由
將 csv 文件解析為矩陣
(
Predict
函數(shù)) 使用不同算法計算向量之間的距離在執(zhí)行此步驟時,所有非數(shù)字字段都將被刪除。非數(shù)字字段被假定為該模型正在訓練的標簽。
歐幾里得
曼哈頓
余弦
類別/標簽或
Attributes
定義在csv
, 在預測列表中返回,一對形式的值(index,predicted Attribute)
。
我如何有選擇地傳入預測變量并預測
在knn
您可以通過將 csv 中的預測目標標記為非整數(shù)值來做到這一點。例如 ( Iris-setosa
, Iris-versicolor
)。
線性回歸
你可以使用AddClassAttribute()
,這個方法是在DenseInstances
struct 上定義的,它是base.ParseCSVToInstances()
方法的輸出。
這樣做的代碼看起來像
instances, err := base.ParseCSVToInstances("../examples/datasets/exams.csv", true) // true: means first line of csv is headers.
attrArray:=instances.AllAttributes()
instances.SetClassAttribute(attrArray[4])//setting final column as class attribute, note that there cannot be more than one class attribute for linear regression.
trainData, testData := base.InstancesTrainTestSplit(instances, 0.1)
lr := NewLinearRegression()
err := lr.Fit(instances)
if err!=nil{
// error handling
}
predictions, err := lr.Predict(testData)
if err!=nil{
// error handling
}
警告:-> 在線性回歸給出的測試文件中,所有這些都沒有完成。我不會聲稱上述方法是分配回歸目標的正確方法或最佳方法。
這是一種可能的方式。它成為線性回歸函數(shù)的候選對象Fit(),這是該模型的計算發(fā)生的地方。Predict()函數(shù)僅將有限的線性回歸系數(shù)集相乘并將該值存儲為預測。
- 1 回答
- 0 關注
- 159 瀏覽
添加回答
舉報