Closed diogoalvesderesende closed 4 years ago
In the README.md =>
from CHAID import Tree
## create the data
ndarr = np.array(([1, 2, 3] * 5) + ([2, 2, 3] * 5)).reshape(10, 3)
df = pd.DataFrame(ndarr)
df.columns = ['a', 'b', 'c']
arr = np.array(([1] * 5) + ([2] * 5))
df['d'] = arr
>>> df
a b c d
0 1 2 3 1
1 1 2 3 1
2 1 2 3 1
3 1 2 3 1
4 1 2 3 1
5 2 2 3 2
6 2 2 3 2
7 2 2 3 2
8 2 2 3 2
9 2 2 3 2
## set the CHAID input parameters
independent_variable_columns = ['a', 'b', 'c']
dep_variable = 'd'
## create the Tree via pandas
tree = Tree.from_pandas_df(df, dict(zip(independent_variable_columns, ['nominal'] * 3)), dep_variable)
## create the same tree, but without pandas helper
tree = Tree.from_numpy(ndarr, arr, split_titles=['a', 'b', 'c'], min_child_node_size=5)
Most likely you just need to:
from CHAID import Tree
Tree.from_numpy(X, Y)
emphasis on the capital 'T'.
Let me know if this helps. If not, feel free to send a worked example over.
(it looks like you've already created your tree in that example - it's a class method so only applies to the Tree class, not the instance variable)
It was the capital T missing. Newbie mistake. Thanks a lot for the follow up!
Hi!
I think it is really great that you did this package. CHAID is a wonderful and useful technique. I tried to use errors but I get the following error:
Do you know what I am doing wrong?
Thanks in advance!