Skip to main content

SciKit learn wrapper for XCS algorithm implementation.

Project description

skxcs

skxcs is a SciKit learn wrapper for implementation of XCS algorithm xcs.

Installation

Use the package manager pip to install skxcs.

pip install skxcs

Usage

Numeric Values

from skxcs.classifiers import XcsClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

# Numeric values
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)

classifier = XcsClassifier()

# If data input is non binary, classifier automatically uses MLDP discretizer for numeric values
# and one hot encoding for categorical values to transform data in both fit and predict methods.

classifier.fit(X_train, y_train)

# Get prediction array
y_pred = classifier.predict(X_test)

# Get pretty rules
for rule in classifier.get_pretty_rules():
    print(rule)

# To use get_pretty_rules or pretty_print_prediction methods,
# classifier has to transform train and test data first.

Categorical values

import pandas as pd
from skxcs.classifiers import XcsClassifier
from sklearn.model_selection import train_test_split

# Categorical values
categorical_frame = pd.read_csv(
    "https://archive.ics.uci.edu/ml/machine-learning-databases/autos/imports-85.data",
    header=None, na_values="?").dropna()
y = categorical_frame[0]
X = categorical_frame.select_dtypes(include=[object])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
classifier = XcsClassifier()

# You can transform data yourself. You should either transform both training
# and testing data, or none of them. It is necessary to ensure correct values are passed to classifier.
X_train_bin = classifier.transform_df(X_train, y=y_train)
classifier.fit(X_train_bin, y_train)

# Note that we don't pass 'y' to transform method when we transform test data
X_test_bin = classifier.transform_df(X_test)

# pretty print prediction
result = classifier.pretty_print_prediction(X_test_bin)
print(result)

Contributing

...

License

MIT

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for skxcs, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size skxcs-0.1-py3-none-any.whl (7.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size skxcs-0.1.tar.gz (6.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page