# Issues with fit! and DecisionTreeRegressor

**URL:** <https://discourse.julialang.org/t/issues-with-fit-and-decisiontreeregressor/8965>\
**Category:** New to Julia\
**Created:** [February 10, 2018, 12:47am UTC](https://discourse.julialang.org/t/issues-with-fit-and-decisiontreeregressor/8965 "2018-02-10T00:47:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max-Zara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/max-zara/32/3393_2.png) [@Max-Zara](https://discourse.julialang.org/u/Max-Zara)\
**Post date:** [February 10, 2018, 12:47am UTC](https://discourse.julialang.org/t/issues-with-fit-and-decisiontreeregressor/8965/1 "2018-02-10T00:47:34Z")

</div>

I’m trying to go through the code in Julia for DataScience and this line does not work:  
fit!(regr\_1, XX, y)

in:

srand(100)  
X = sort(5 \* rand(80))  
XX = reshape(X, 80, 1)  
y = sin(X)  
y[1:5:end] += 3 \* (0.5 - rand(16))

# Fit regression model

regr\_1 = DecisionTreeRegressor()  
regr\_2 = DecisionTreeRegressor(pruning\_purity\_threshold=0.05)

fit!(regr\_1, XX, y)

fit!(regr\_2, XX, y)

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [February 10, 2018, 8:29am UTC](https://discourse.julialang.org/t/issues-with-fit-and-decisiontreeregressor/8965/2 "2018-02-10T08:29:22Z")

</div>

Not sure what package provides `DecisionTreeRegressor`, but usually the convention is something like,

```julia
model = DecisionTreeRegressor(XX, y)
fit!(model)

```

and with keyword arguments,

```julia
model = DecisionTreeRegressor(XX, y, pruning_purity_threshold = 0.05)
fit!(model)

```

or

```julia
model = DecisionTreeRegressor(XX, y)
fit!(model, pruning_purity_threshold = 0.05)

```

---

<div class="post-metadata">

**Author:** ![ValdarT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valdart/32/24146_2.png) [@ValdarT](https://discourse.julialang.org/u/ValdarT)\
**Post date:** [February 10, 2018, 10:43am UTC](https://discourse.julialang.org/t/issues-with-fit-and-decisiontreeregressor/8965/3 "2018-02-10T10:43:33Z")

</div>

This code works fine for me (need to load the package with `using DecisionTree`, of course). What is the exact error message you are getting?

---

<div class="post-metadata">

**Author:** ![Max-Zara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/max-zara/32/3393_2.png) [@Max-Zara](https://discourse.julialang.org/u/Max-Zara)\
**Post date:** [February 11, 2018, 3:21pm UTC](https://discourse.julialang.org/t/issues-with-fit-and-decisiontreeregressor/8965/4 "2018-02-11T15:21:40Z")

</div>

It seems the computer needed a reboot to load the packages after Pkg.add(“DecisionTree”) This has happened with several other packages previously.
