Coder Social home page Coder Social logo

scikit-learn-c4.5's Introduction

scikit-learn C4.5 classifier

This is a C4.5 classifier compatible with scikit-learn, and more precisely, with scikit-learn.model_selection.GridSearchCV.

This repo is forked from RaczeQ/scikit-learn-C4.5-tree-classifier, which is in turn based on zhangchiyu10/pyC45.

Example usage

It is important to pass the feature names to the constructor. In case you use a column transformer, you will need to know the column names beforehand by executing the transformer before the grid search pipeline.

Example usage can be found in a main.py file:

from imblearn.pipeline import Pipeline
from sklearn.compose import make_column_transformer
from sklearn.decomposition import PCA  # for example

from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeClassifier  # to have another model to check

from c45 import C45

categorical_preprocessing = make_column_transformer(
    ...,
    remainder='passthrough',
    verbose_feature_names_out=False
)

X_tr = categorical_preprocessing.fit_transform(X)
feature_names = categorical_preprocessing.get_feature_names_out()


pipe = Pipeline([
    ('dimensionality_reduction', 'passthrough'),
    ('clf', 'passthrough')
])

param_grid = {
    'dimensionality_reduction': [
        'passthrough',
        PCA()
    ],
    'clf': [
        *[DecisionTreeClassifier(
            random_state=19,
            criterion=prd['criterion'],
            #max_features=prd['max_features'],
            max_depth=prd['max_depth']
        ) for prd in product_dict(
            #max_features=[None, 'sqrt', 'log2'],
            max_depth=[4,5,6,7,8,9,10,None],
            criterion=['gini', 'entropy', 'log_loss'], 
        )],
        C45(attrNames_=feature_names[:-1])
    ]
}

cv = GridSearchCV(pipe, param_grid=param_grid, scoring='accuracy', cv=5, n_jobs=-1, verbose=10)
cv.fit(X_tr, y)

scikit-learn-c4.5's People

Contributors

raczeq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.