Comments (2)
The issue is not with the function, I see the issue is with passing predicted values instead of actual values (sorted by the predicted values) in the code for the Figure 5.2 on page 132
pred_v = pd.Series(reg.predict(valid_X)) pred_v = pred_v.sort_values(ascending=False)
pred_v needs to be actual actual prices sorted by these predictions when passed to GainsChart()
from dmba.
Hello Matt,
You are right, we identified this issue in the book about a year ago and (hopefully) fixed it with the following code. I can see that Wiley hasn't corrected the problem in the electronic version yet. It was also not yet corrected in the code available through the book's website.
Code for Figure 5.2:
# sort the actual values in descending order of the prediction
df = pd.DataFrame({
'predicted': reg.predict(valid_X),
'actual': valid_y,
})
df = df.sort_values(by=['predicted'], ascending=False)
fig, axes = plt.subplots(nrows=1, ncols=2)
ax = gainsChart(df['actual'], ax=axes[0])
ax.set_ylabel('Cumulative Price')
ax.set_title('Cumulative Gains Chart')
ax = liftChart(df['actual'], ax=axes[1], labelBars=False)
ax.set_ylabel('Lift')
plt.tight_layout()
plt.show()
The code for figure 10.3 also needs correcting:
df = logit_result.sort_values(by=['p(1)'], ascending=False)
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 4))
gainsChart(df.actual, ax=axes[0])
liftChart(df.actual, title=False, ax=axes[1])
plt.tight_layout()
plt.show()
In this case, the call to liftChart
was incorrect.
from dmba.
Related Issues (12)
- Distribute data sets with package
- Replace pydotplus with the graphviz package
- plotDecisionTree not working HOT 2
- Fails without ipython support HOT 5
- Control size of graph representation from graphviz
- Skip setting matplotlib backend in colab notebooks
- Code HOT 7
- Improve error message when graphviz is not installed
- Check the dimensionality of the arrays and flatten if appropriate.
- Windows 10, DISPLAY, and matplotlib HOT 3
- gainsChart and liftChart have issues with pandas 1.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dmba.