Comments (9)
Hello, did you test the accuracy of the transpiled estimator?
porter = Porter(clf, language='java')
accuracy = porter.predict_test(X)
print(accuracy)
from sklearn-porter.
0.0
is the worst case scenario. The question is why did the transpiled estimator return always the same label. Can you post the transpiled output? Did you preprocess the data?
from sklearn-porter.
Okay, that looks good. Can you post some samples which you used for the training (.fit()
)?
from sklearn-porter.
Thanks for the help nok, I got this:
from sklearn-porter.
The transpiled output?... which is that?. My data is just numbers, the weird thing is that when I train without sklearn porter I get 70% of accuracy when I calculate it with acc_score
from sklearn-porter.
print(Porter(clf, language='java').export())
prints the transpiled estimator. The method predict_test
compares the predictions from the original estimator in Python with the predictions from your target programming language. So the accuracy of your trained estimator doesn't matter.
from sklearn-porter.
This is the transpiled estimator:
class Brain {
public static int predict(double[] atts) {
if (atts.length != 3) {
return -1;
}
int i, j;
double[] priors = {0.72410256410256413, 0.27589743589743587};
double[][] sigmas = {{7777.674409056468, 2946.6863403262582, 1470.3790926152326}, {20368.196235029616, 7677.4899510244086, 3792.4066470154612}};
double[][] thetas = {{2.1022332039660077, -1.1895209475920669, 2.4095972967422088}, {1.1423813271375469, -4.613826715613385, 6.9545192825278832}};
double[] likelihoods = new double[2];
for (i = 0; i < 2; i++) {
double sum = 0.;
for (j = 0; j < 3; j++) {
sum += Math.log(2. * Math.PI * sigmas[i][j]);
}
double nij = -0.5 * sum;
sum = 0.;
for (j = 0; j < 3; j++) {
sum += Math.pow(atts[j] - thetas[i][j], 2.) / sigmas[i][j];
}
nij -= 0.5 * sum;
likelihoods[i] = Math.log(priors[i]) + nij;
}
double highestLikeli = Double.NEGATIVE_INFINITY;
int classIndex = -1;
for (i = 0; i < 2; i++) {
if (likelihoods[i] > highestLikeli) {
highestLikeli = likelihoods[i];
classIndex = i;
}
}
return classIndex;
}
public static void main(String[] args) {
if (args.length == 3) {
double[] atts = new double[args.length];
for (int i = 0, l = args.length; i < l; i++) {
atts[i] = Double.parseDouble(args[i]);
}
System.out.println(Brain.predict(atts));
}
}
}
from sklearn-porter.
@nok Here is the data I am using to train the model. I am still having issues in the java side, don't understand why I am always predicting the same label. Here's how I am using the prediction method:
] = rollValue;
values[1] = pitchValue;
values[2] = yawValue;
//values[3] = gxValue;
//values[4] = gyValue;
//values[5] = gzValue;
int y_pred = Brain.predict(values);
ClassifierLog.setText(Integer.toString(y_pred));
System.out.println("pred: " + Integer.toString(y_pred));
int counter = 0;
//Simple threshold
if (rollValue < -40 && rollValue > -80
&& pitchValue < 0 && yawValue > 0
&& gxValue < 1000 && gxValue > -2000
&& gyValue < 500 && gyValue > -1000
&& gzValue < 1000 && gzValue > -2000) {
ClassifierLog.setText("N");
System.out.println("COUNTER: " + counter);
} else {
counter++;
ClassifierLog.setText("W");
System.out.println("COUNTER: " + counter);
}
}
from sklearn-porter.
Hello @alonsopg ,
first of all sorry for my late response. Can you share your data again please? And I guess you use the default parameters for the GaussianNB classifier?
Best,
Darius
from sklearn-porter.
Related Issues (20)
- Feature Request: translator for onehot encoder
- Feature Request: Multinomial Logistic Regression
- A bug : When the version of sklearn contains character sequences like "rc1, rc2", the Porter class cannot be created. HOT 1
- RandomForestClassifier export HOT 1
- decision tree C code exported by porter have zero integrity score with custom test_data. HOT 1
- Test code, which is part of the Readme is failing HOT 2
- [Query] Is the isolation forest model for outlier detection supported now? HOT 1
- ValueError: invalid literal for int() with base 10: 'post1' on Example from Readme HOT 2
- What does embed_data do?
- [Enhancement]Background concurrent copying GC freed for sklearn model constrcutor in Java HOT 2
- [Error] Works fine with C but getting this error when ported to Java
- OSError: Windows isn't supported yet HOT 3
- Unable to check integrity score. HOT 1
- Generating probabilities instead of categorical results
- scikit-learn-0.24.1: ModuleNotFoundError: No module named 'sklearn.tree.tree' HOT 5
- Is there any plan to support RandomForestRegressor? HOT 11
- ImportError: cannot import name 'Porter' HOT 2
- Can't use port or save functions HOT 3
- ModuleNotFoundError: No module named 'sklearn_porter' HOT 1
- ModuleNotFoundError: No module named 'sklearn.tree.tree' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sklearn-porter.