Skip to content

Instantly share code, notes, and snippets.

@Khalifa1997
Created March 31, 2020 20:37
Show Gist options
  • Save Khalifa1997/7dd89914977b0887c32526900751862c to your computer and use it in GitHub Desktop.
Save Khalifa1997/7dd89914977b0887c32526900751862c to your computer and use it in GitHub Desktop.
from shogun import csv_file
from shogun import features
from shogun import labels
from shogun import machine
import pickle
f_feats_train = csv_file("/path/to/shogun/build/examples/meta/data/regression_1d_linear_features_train.dat")
f_feats_test = csv_file("/path/to/shogun/build/examples/meta/data/regression_1d_linear_features_test.dat")
f_labels_train = csv_file("/path/to/shogun/build/examples/meta/data/regression_1d_linear_labels_train.dat")
f_labels_test = csv_file("/path/to/shogun/build/examples/meta/data/regression_1d_linear_labels_test.dat")
features_train = features(f_feats_train)
features_test = features(f_feats_test)
labels_train = labels(f_labels_train)
labels_test = labels(f_labels_test)
lrr = machine("LinearRidgeRegression", tau=0.001, labels=labels_train)
lrr.train(features_train)
labels_predict = lrr.apply(features_test)
pickle.dump(lrr, open('model.pkl','wb'))
model = pickle.load(open('model.pkl','rb'))
@Khalifa1997
Copy link
Author

The Traceback can be found here:

Traceback (most recent call last):
  File "/home/ahmed/Desktop/shogun/build/src/interfaces/python/shogun.py", line 192, in _sg_reconstructor
    return eval(cls+'()')
  File "<string>", line 1, in <module>
AttributeError: module 'shogun' has no attribute 'LinearRidgeRegression'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ahmed/PycharmProjects/demo/main.py", line 23, in <module>
    model = pickle.load(open('model.pkl','rb'))
  File "/home/ahmed/Desktop/shogun/build/src/interfaces/python/shogun.py", line 209, in _sg_reconstructor
    return _py_orig_reconstructor(cls, base, state)
  File "/usr/lib/python3.6/copyreg.py", line 43, in _reconstructor
    obj = object.__new__(cls)
TypeError: object.__new__(X): X is not a type object (str)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment