How to use the sklearn.externals.joblib function in sklearn

To help you get started, we’ve selected a few sklearn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rbaravalle / imfractal / tests / test_classifier_sea.py View on Github external
tr = args.transform[0]
    if tr in transformation_values:
        transform_str = tr
        if args.equalize[0] in true_values:
            transform_str += '_eq'
    else:
        transform_str = "no_transform"
    dfs_str = str(args.dfs[0])

    clf = cfr.fit(X_train, y_train)
    outdir_clf=filename_model_RF_tt.format(resol, transform_str, dfs_str)
    if not os.path.exists(model_directory):
        os.makedirs(model_directory)
    print "Saving classifier...",  outdir_clf
    joblib.dump(clf, outdir_clf) 
        
    clf2 = cfr2.fit(X_train, y_train)
    outdir_clf2=filename_model_SVC_tt.format(resol, transform_str, dfs_str)
    print "Saving classifier...", outdir_clf2
    joblib.dump(clf2, outdir_clf2)
    
    print "RF, SVM: " + str( round(clf.score(X_test, y_test), 4) ) + " " + str( round(clf2.score(X_test, y_test), 4) )
github GoogleCloudPlatform / cloudml-samples / sklearn / iris_training.py View on Github external
iris_data = pd.read_csv(iris_data_filename).values
iris_target = pd.read_csv(iris_target_filename).values

# Convert one-column 2D array into 1D array for use with scikit-learn
iris_target = iris_target.reshape((iris_target.size,))
# [END load-into-pandas]


# [START train-and-save-model]
# Train the model
classifier = svm.SVC(gamma='auto', verbose=True)
classifier.fit(iris_data, iris_target)

# Export the classifier to a file
model_filename = 'model.joblib'
joblib.dump(classifier, model_filename)
# [END train-and-save-model]


# [START upload-model]
# Upload the saved model file to Cloud Storage
gcs_model_path = os.path.join('gs://', BUCKET_NAME,
    datetime.datetime.now().strftime('iris_%Y%m%d_%H%M%S'), model_filename)
subprocess.check_call(['gsutil', 'cp', model_filename, gcs_model_path],
    stderr=sys.stdout)
# [END upload-model]
github GuiltyNeuron / ANPR / Licence_plate_recognition / Tunisian_plates / ml.py View on Github external
clf = MLPClassifier(solver='adam', alpha=1e-5, hidden_layer_sizes=3000, random_state=1, max_iter=200000)

    # Training
    clf.fit(x_train, y_train)

    # Testing
    y_pred = clf.predict(x_test)

    # Confusion matrix
    cm = confusion_matrix(y_test, y_pred)

    # Accuracy
    accuracy = clf.score(x_test, y_test)

    # Saving the model
    joblib.dump(clf, output_file_path)

    print("\n-- Multi Layer Perceptron --")
    print("Training completed")
    print("Accuracy : " + str(accuracy))
    print("Confusion Matrix :")
    print(cm)
github FreeDiscovery / FreeDiscovery / freediscovery / engine / lsi.py View on Github external
mid_dir_base = dsid_dir / self._wrapper_type

        mid, mid_dir = setup_model(mid_dir_base, mid=self.mid, mode=self.mode)

        ds = self.pipeline.data
        n_components_opt = _compute_lsi_dimensionality(n_components, *ds.shape,
                                                       alpha=alpha)
        svd = _TruncatedSVD_LSI(n_components=n_components_opt,
                                n_iter=n_iter, random_state=self.random_state)
        lsi = svd
        lsi.fit(ds)

        ds_p = lsi.transform_lsi_norm(ds)

        joblib.dump(pars, str(mid_dir / 'pars'))
        joblib.dump(lsi, str(mid_dir / 'model'))
        joblib.dump(ds_p, str(mid_dir / 'data'))

        exp_var = lsi.explained_variance_ratio_.sum()
        self.mid = mid

        return lsi, exp_var
github ybhartia / 170Starcraft / svmImplementation.py View on Github external
def trainReplays(xTrainData, yTrainData):

	#
	# Polynomial model with degree 1
	#
	clfPoly = svm.SVC(kernel='poly', degree=1) # Since input layer should be small
	clfPoly.fit(xTrainData, yTrainData)
	joblib.dump(clfPoly, 'clfPoly.pkl')

	#
	# Linear Model
	#
	clfLinear = svm.SVC(kernel='linear') 
	clfLinear.fit(xTrainData, yTrainData)
	joblib.dump(clfLinear, 'clfLinear.pkl')

	#
	# Sigmoid Model
	#
	clfSigmoid = svm.SVC(kernel='sigmoid')
	clfSigmoid.fit(xTrainData, yTrainData) 
	joblib.dump(clfSigmoid, 'clfSigmoid.pkl')
github gprana / READMEClassifier / script / classifier_train_model_predict_proba.py View on Github external
features_tfidf = pandas.DataFrame(tfidfX.todense())
        # Assign column names to make it easier to print most useful features later
        features_tfidf.columns = tfidf.get_feature_names()
        features_combined = pandas.concat([features_tfidf, derived_features], axis=1)
        
        logging.info('Combined features shape:')
        logging.info(features_combined.shape)
        
        svm_object = LinearSVC() 
        clf = CalibratedClassifierCV(svm_object) 
        classifier = balancer.OneVsRestClassifierBalance(clf)
        
        logging.info('Training classifier')
        classifier.fit(features_combined.values, labels_matrix) 
        logging.info('Saving TFIDF vectorizer')
        joblib.dump(tfidf, vectorizer_filename)
        logging.info('Saving binarizer')
        joblib.dump(mlb, binarizer_filename)
        logging.info('Saving model')
        joblib.dump(classifier, model_filename)
                
        end = time.time()
        runtime_in_seconds = end - start
        logging.info('Processing completed in {0}'.format(runtime_in_seconds))
    except Error as e:
        logging.exception(e)
    except Exception as e:
        logging.exception(e)
    finally:
        conn.close()
github PINTO0309 / PINTO_model_zoo / 15_Faster-Grad-CAM / janken_demo_tflite.py View on Github external
try:
    from tflite_runtime.interpreter import Interpreter
except:
    from tensorflow.lite.python.interpreter import Interpreter

model_path = "model/" 

if os.path.exists(model_path):
    # load csv 
    print("csv loading...")
    channel_weight = np.loadtxt(model_path + "channel_weight.csv", delimiter=",")
    channel_adress = np.loadtxt(model_path + "channel_adress.csv", delimiter=",", dtype="float")
    channel_adress = channel_adress.astype(np.int)
    vector_pa = np.loadtxt(model_path + "vector_pa.csv", delimiter=",")
    kmeans = joblib.load(model_path + "k-means.pkl.cmp")

else:
    print("Nothing model folder")

def get_score_arc(pa_vector, test):
    # cosine similarity
    cos_similarity = cosine_similarity(test, pa_vector)

    return np.max(cos_similarity)

def cosine_similarity(x1, x2): 
    if x1.ndim == 1:
        x1 = x1[np.newaxis]
    if x2.ndim == 1:
        x2 = x2[np.newaxis]
    x1_norm = np.linalg.norm(x1, axis=1)
github neptune-ml / open-solution-mapping-challenge / src / steps / keras / embeddings.py View on Github external
def load(self, filepath):
        self.embedding_matrix = joblib.load(filepath)
        return self
github neptune-ml / steppy-toolkit / toolkit / lightgbm_transformers / models.py View on Github external
def persist(self, filepath):
        joblib.dump(self.estimator, filepath)
github OSGeo / grass-addons / grass7 / raster / r.learn.ml / rlearn_utils.py View on Github external
def load_model(filename):
    from sklearn.externals import joblib
    
    estimator, X, y, sample_coords, groups = joblib.load(filename)

    return (estimator, X, y, sample_coords, groups)