<jupyter_start><jupyter_text>Load Arff file into Scikit-learnSource: [Stackoverflow.com](http://stackoverflow.com/questions/22873434/prepare-scipy-io-loadarff-result-for-scikit-learn)<jupyter_code>from sklearn.ensemble import RandomForestClassifier
from scipy.io.arff import loadarff

import scipy as sp
import numpy as np

dataset = loadarff(open('iris.arff','r'))
target = np.array(dataset[0]['class'])
train = np.array(dataset[0][['sepallength', 'sepalwidth', 'petallength', 'petalwidth']])
train = np.asarray(train.tolist(), dtype=np.float32)
rf = RandomForestClassifier(n_estimators = 20, n_jobs = 8)
rf.fit(train, target)
print(rf)

# -----------------------
arffFile = 'iris.arff'  # get it here http://www.cas.mcmaster.ca/~cs4tf3/iris.arff
# -----------------------

with open(arffFile,'r') as f:
    data, meta = loadarff(f)

print(type(data)) # <class 'numpy.ndarray'> 
print(type(meta)) # <class 'scipy.io.arff.arffread.MetaData'>

train = data[meta.names()[:-1]] #everything but the last column
train = train.view(np.float).reshape(data.shape + (-1,)) #converts the record array to a normal numpy array<jupyter_output>RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
            max_depth=None, max_features='auto', max_leaf_nodes=None,
            min_samples_leaf=1, min_samples_split=2,
            min_weight_fraction_leaf=0.0, n_estimators=20, n_jobs=8,
            oob_score=False, random_state=None, verbose=0,
            warm_start=False)
<class 'numpy.ndarray'>
<class 'scipy.io.arff.arffread.MetaData'>
{'fraction_non_alphanumeric': 0.1720360824742268, 'fraction_numerical': 0.017396907216494846, 'mean_word_length': 4.43006993006993, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '570223', 'license': 'CC0-1.0', 'n_tokens_mistral': 579, 'n_tokens_neox': 561, 'n_words': 97, 'path': 'ipynb/[scikit-learn, scipy] load arff databases.ipynb', 'repo_name': 'mamrehn/machine-learning-tutorials', 'size': '1552'}