Package: ngocbienml
This is a machine learning tools with pipeline.
You can use it for binary classification or regression task.
Here some example to run machine learning project:fromngocbienmlimportMyPipelinepipeline=MyPipeline()pipeline.fit(data,target)pipeline.score(new_data,new_target)OrfromngocbienmlimportPipelineKfoldpipline=PipelineKfold()pipline.fit(data,target)pipline.score(new_data,new_target)Some params forMyPipeline,PipelineKfold:objectivebebinaryorregressionmodel_namebelgborlogisticto use lgbm model or linear sklearn modelmodelif setNone, will be usemodel_nameto pick model, otherwise, use direct this defined model. In case wheremodelparams is notNonemodel_namewill be ignored.Where data is pandas dataframe, target is series object. In the above default settting, principal modules of pipeline
are:Fillna by meanLabelEncoderFeature Selection: Use 2 methods: variance and correlationMinMaxScaleLGBClassifier: The default params work well with dataset of 100K rows or more, with minimum of 20 features. It deals
well with unbalanced dataset. In the above default setting 10% of dataset will be cut for test set if not using kfold
or 5 folds in other case.You can use to save and reload pipeline for a long usage.fromjoblibimportdump,loadfromngocbienmlimportMyPipelinepipeline=MyPipeline()dump(pipeline,path)pipeline=load(path)pipeline.score(data,target)You can use include many preprocessing classes like Fillna, Scale, or Labelencoder in your customized pipeline. Note
that actually, you can not use full label encoder by sklearnfromngocbienmlimportMinMaxScale,Fillna,LabelEncoder,ModelWithPipelinefromsklearn.pipelineimportPipelinepipeline=Pipeline([('label_encoder',LabelEncoder()),('fillna',Fillna()),('scale',MinMaxScale()),('model',ModelWithPipeline())])pipeline.fit(data,target)pipeline.score(test,y_test)fromngocbienmlimportPipelineKfoldpipeline=PipelineKfold()pipeline.fit(data,target)pipeline.score(test,y_test)We can use only pipeline to transform data, and then use it for other taskfromngocbienmlimportAssertGoodHeader,Fillna,LabelEncoder,FeatureSelection,FillnaAndDropCatFeat,MinMaxScalefromsklearn.pipelineimportPipelinesteps=[('assertGoodheader',AssertGoodHeader()),('Fillna',Fillna()),('LabelEncoder',LabelEncoder()),('FillnaAndDropCatFeat',FillnaAndDropCatFeat()),('MinMaxScale',MinMaxScale()),('FeatureSelection',FeatureSelection())]pipline=Pipeline(steps=steps)data="numpy array or pd.DataFrame"df_transformed=pipline.fit_transform(data)Or the simplest way is to use the default paramsfromngocbienmlimportMyPipelinepipline=MyPipeline(model_name=None)# do not use model in this casedata="numpy array or pd.DataFrame"df_transformed=pipline.fit_transform(data)In the above code, df_tranformed is numeric data frame with the same header of df. df_transformed is ready to train by
any model.fromsklearn.linear_modelimportLogisticRegressionclassifier=LogisticRegression()classifier.fit(df_transformed,label)You can run deeplearning, for examplefromngocbienmlimportDeepLearningModelclassifier=DeepLearningModel(model_name='dl',objective='regression',epochs=3000,hidden_layers=[64,32],activation=['relu','sigmoid'],dropout=.1)classifier.fit(data,target)Note that all above model can run binary classification or regression. To setup for regression, please useobjectiveparams, for examplefromngocbienmlimportPipelineWithKfoldmodel=PipelineWithKfold(objective="regression",model_name="lgb")# this will create regression modelmodel.fit(data,target)You can pass a specific model to the piplineobjective="binary"# or regressionmodel="some model with correct objective"pipeline=MyPipeline(objective=objective,model=model)pipeline.fit(data,target)Use search cv for hyper params tuning:fromngocbienmlimportSearchCvSearchCv(n_iter=100).fit(data,target)This tool will break down n_iter to small step and save at the and of these step, to ensure that you do not loss
everything if you shut down your PC before the end of running. You can re-runing this to refit and fit the better paramsWhat's next:More setting in feature extraction and modelling.More metric and visualization