Problem code: (negligible code)
import numpy as np
from sklearn.feature_selection import SelectKBest, f_classif
import matplotlib.pyplot as plt
predictors = ["Pclass", "Sex", "Age", "SibSp", "Parch", "Fare", "Embarked", "FamilySize", "Title", "NameLength"]
# Perform feature selection
selector = SelectKBest(f_classif, k=5)
selector.fit(titanic[predictors], titanic["Survived"])
# Get the raw p-values for each feature, and transform from p-values into scores
scores = -np.log10(selector.pvalues_)
# Plot the scores. See how "Pclass", "Sex", "Title", and "Fare" are the best?
plt.bar(range(len(predictors)), scores)
plt.xticks(range(len(predictors)), predictors, rotation='vertical')
plt.show()
# Pick only the four best features.
predictors = ["Pclass", "Sex", "Fare", "Title"]
alg = RandomForestClassifier(random_state=1, n_estimators=50, min_samples_split=8, min_samples_leaf=4)
Running results:
& lt; figure size 640x480 with 1 axes & gt;
no pictures are displayed
Solution:
Add % Matplotlib inline
to the code header
import pandas #ipython notebook
titanic = pandas.read_csv("titanic_train.csv")
titanic.head(5)
#print (titanic.describe())
%matplotlib inline
Read More:
- Python Anaconda Spyder can’t display pictures by using Matplotlib. Error report solution: figures now render in the plots pane by default. To mak
- Exception: jupyter command Jupiter notebook not found
- RuntimeError: Expected hidden[0] size (x, x, x), got(x, x, x)
- Error importing keras in jupyter Notebook: modulenotfounderror: no module named ‘keras’ solution
- [Fixed]Error executing Jupyter command ‘notebook’: [Errno ‘jupyter-notebook’ not found] 2
- Change Jupyter Notebook Default Directory
- Setting up a virtual environment for jupyter notebook
- Error kernel restart: restart failed was reported in the background of jupyter notebook
- On the kernel error of jupyter notebook
- Nginx manager jupyter notebook v1.0.0 http websocket
- Error converting jupyter notebook to PDF
- How to solve the problem of creating notebook failed
- Solve the problem of using in tensoft 2. X tf.contrib.slim No module named appears in the package: tensorflow.contrib problem
- Jupyter notebook couldn’t find CONDA’s virtual environment
- Error in loading online pictures on billboard in cesium tainted canvas may not be loaded
- Vs code solves the problem that latex does not display references and [?] is displayed in the text
- In Python, import XXX does not report an error, but in IPython (Jupiter notebook)
- [Solved] Jupyter Notebook Error 500: Internal Server Error
- Error in `./a.out‘: free(): invalid next size (fast): 0x0000000001da8010
- display:inline-block Solution to the gap problem