pa-m / sklearn Goto Github PK
View Code? Open in Web Editor NEWbits of sklearn ported to Go #golang
License: MIT License
bits of sklearn ported to Go #golang
License: MIT License
I'm playing with pa-m/sklearn and wrote simple code to classify iris with svm.
package main
import (
"fmt"
"time"
"github.com/pa-m/sklearn/datasets"
"github.com/pa-m/sklearn/metrics"
modelselection "github.com/pa-m/sklearn/model_selection"
"github.com/pa-m/sklearn/preprocessing"
"github.com/pa-m/sklearn/svm"
"gonum.org/v1/gonum/mat"
)
func main() {
ds := datasets.LoadIris()
X1 := ds.X
yscaler := preprocessing.NewMinMaxScaler([]float64{-1, 1})
Y1, _ := yscaler.FitTransform(ds.Y, nil)
Xtrain, Xtest, Ytrain, Ytest := modelselection.TrainTestSplit(X1, Y1, 0.25, uint64(time.Now().UnixNano()))
clf := svm.NewSVC()
clf.C = 0.1
clf.Kernel = "rbf"
clf.Fit(Xtrain, Ytrain)
_ = Xtest
_ = Ytest
result := mat.NewDense(Ytest.RawMatrix().Rows, 1, nil)
clf.Predict(Xtest, result)
fmt.Println(mat.Formatted(result))
fmt.Printf("%.02f%%\n", metrics.AccuracyScore(result, Ytest, true, nil)*100)
}
This is based on Python code.
import sklearn.datasets
import sklearn.model_selection
import sklearn.metrics
import sklearn.svm
iris = sklearn.datasets.load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test =\
sklearn.model_selection.train_test_split(X, y, test_size=0.25, random_state=1234)
clf = sklearn.svm.SVC(kernel='rbf', C=0.1)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
score = sklearn.metrics.accuracy_score(y_test, y_pred)
print(score)
Go code don't finish training. Is this something wrong?
I find DecisionTreeClassifier api every docs but can not get any api about DecisionTreeClassifier? please tell me how can I use DecisionTreeClassifier model trained by python with this lib. Thanks a lot.
as the title,i want to know,how load pkl file with golang.i train model in python with sklearn,it saved as model.pkl
,then how i load it in golang? pls
Golang newbie here. So, I trained a KNN on python and new project requirements need me to deploy on Golang. I saw a few of the questions here, but I can't see a way to use a pre-loaded model. I have tried using npy files and pkl files, but I can't seem to use the predict method the way I would on python. How should I proceed?
Thanks.
Good day! Suppose I have this code
package main
import (
"fmt"
"github.com/pa-m/sklearn/neighbors"
"gonum.org/v1/gonum/mat"
)
func main() {
X := mat.NewDense(5, 4, []float64{0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1})
nbrs := neighbors.NewNearestNeighbors()
nbrs.Fit(X, mat.Matrix(nil))
distances, indices := nbrs.KNeighbors(X, 5)
fmt.Println(distances)
fmt.Println()
fmt.Println(indices)
}
The result gives me this
&{{5 5 [0 1 1 1.4142135623730951 2 0 1.4142135623730951 1.7320508075688772 1.7320508075688772 2 0 1 1 1.4142135623730951 1.7320508075688772 0 1 1.4142135623730951 1.7320508075688772 1.7320508075688772 0 1 1.4142135623730951 1.4142135623730951 1.7320508075688772] 5} 5 5}
&{{5 5 [0 2 3 4 1 1 4 2 3 0 2 0 4 3 1 3 0 2 1 4 4 2 0 1 3] 5} 5 5}
I'm expecting the result to be like this
[0 1 1 1.4142135623730951 2 0 1.4142135623730951 1.7320508075688772 1.7320508075688772 2 0 1 1 1.4142135623730951 1.7320508075688772 0 1 1.4142135623730951 1.7320508075688772 1.7320508075688772 0 1 1.4142135623730951 1.4142135623730951 1.7320508075688772]
[0 2 3 4 1 1 4 2 3 0 2 0 4 3 1 3 0 2 1 4 4 2 0 1 3]
How can I get the array value from those results as a []float64? I'll appreciate the help.
============================
Update: I already solved my problem.
As of 2704973b509448cfd217eeb036d9db869c80b837
in gonum
the optimize.Local
function has been removed.
This cause the library to fail building
github.com/pa-m/sklearn/linear_model/Base.go:243:15: undefined: optimize.Local
Hello everyone,
I'd like to use MinMaxScaler in my RPi4.
but there is an error while installing.
Are there any ways to use it in my RPi4?
Thank you for the reply in advance.
go: downloading github.com/pa-m/sklearn v0.0.0-20200711083454-beb861ee48b1
go: downloading golang.org/x/exp v0.0.0-20191129062945-2f5052295587
go: downloading github.com/pa-m/optimize v0.0.0-20190612075243-15ee852a6d9a
go: downloading gonum.org/v1/gonum v0.6.1
go: downloading github.com/pa-m/randomkit v0.0.0-20191001073902-db4fd80633df
go: downloading golang.org/x/tools v0.0.0-20200225230052-807dcd883420
# github.com/pa-m/optimize
/home/pi/go/pkg/mod/github.com/pa-m/[email protected]/powell.go:34:16: constant 9223372036854775807 overflows int
/home/pi/go/pkg/mod/github.com/pa-m/[email protected]/powell.go:37:15: constant 9223372036854775807 overflows int
/home/pi/go/pkg/mod/github.com/pa-m/[email protected]/powell.go:40:17: constant 9223372036854775807 overflows int
/home/pi/go/pkg/mod/github.com/pa-m/[email protected]/powell.go:43:14: constant 9223372036854775807 overflows int
I am pyhon programmer and I am learning golang and I would like to help this project bring all features from sklearn to this project.
Where and How can i start?
SVMs with linear kernels can be trained in O(n) time, as in LIBLINEAR.
Can svmTrain fast-path to an O(n) solver when svm.Kernel == "linear"?
Good day! Do you have plans to add Brute Force K-Nearest Neighbor Algorithm for Cosine Similarity Metric? I am looking forward to this feature.
Thanks for this awesome project. I think a lot of existing projects using sklearn (python) are already built and tested in python environment. If there is a solution to allow data scientists to load their sklearn python models (normally they would dump to a pickle and serve in Flask) and serve in Golang, that will be very nice. Any recommendation on how to achieve this: from an existing python model -> serve in Go?
Do you have plans to add the Classifier version of Gaussian Processes?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.