mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-04-28 13:48:56 +08:00
fix: correct base dataframe
This commit is contained in:
parent
9ed5a13fba
commit
e3b68dd8f7
@ -10,26 +10,26 @@ import (
|
|||||||
|
|
||||||
// ConvertDataFrameToInstances converts a DataFrame-go dataframe object to Golearn Fixed Data Grid. Allows for compabitibility between dataframe and golearn's ML models.
|
// ConvertDataFrameToInstances converts a DataFrame-go dataframe object to Golearn Fixed Data Grid. Allows for compabitibility between dataframe and golearn's ML models.
|
||||||
// df is the dataframe Object. classAttrIndex is the index of the class Attribute in the data.i
|
// df is the dataframe Object. classAttrIndex is the index of the class Attribute in the data.i
|
||||||
func ConvertDataFrameToInstances(df *dataframe.DataFrame, classAttrIndex int) base.FixedDataGrid {
|
func ConvertDataFrameToInstances(df *dataframe.DataFrame, classAttrIndex int) FixedDataGrid {
|
||||||
|
|
||||||
// Creating Attributes based on Datafraem
|
// Creating Attributes based on Datafraem
|
||||||
names := df.Names()
|
names := df.Names()
|
||||||
attrs := make([]base.Attribute, len(names))
|
attrs := make([]Attribute, len(names))
|
||||||
|
|
||||||
newInst := base.NewDenseInstances()
|
newInst := NewDenseInstances()
|
||||||
|
|
||||||
for i := range names {
|
for i := range names {
|
||||||
col := df.Series[i]
|
col := df.Series[i]
|
||||||
if reflect.TypeOf(col.Value(0)).Kind() == reflect.String {
|
if reflect.TypeOf(col.Value(0)).Kind() == reflect.String {
|
||||||
attrs[i] = new(base.CategoricalAttribute)
|
attrs[i] = new(CategoricalAttribute)
|
||||||
attrs[i].SetName(names[i])
|
attrs[i].SetName(names[i])
|
||||||
} else {
|
} else {
|
||||||
attrs[i] = base.NewFloatAttribute(names[i])
|
attrs[i] = NewFloatAttribute(names[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the attributes
|
// Add the attributes
|
||||||
newSpecs := make([]base.AttributeSpec, len(attrs))
|
newSpecs := make([]AttributeSpec, len(attrs))
|
||||||
for i, a := range attrs {
|
for i, a := range attrs {
|
||||||
|
|
||||||
newSpecs[i] = newInst.AddAttribute(a)
|
newSpecs[i] = newInst.AddAttribute(a)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user