GraphViz's executables not found error in Anaconda? - python

I wrote the following code to build the decision tree, but I got the following error. can you help me?
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
from six import StringIO
from sklearn.tree import export_graphviz
from sklearn import tree
import pydot
from IPython.display import Image
import pydotplus
import graphviz
dot_data = StringIO()
export_graphviz(decisionTree1, out_file =dot_data, filled=True,
rounded =True, special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(graph.create_png())

If you are using Linux try this in cmd: sudo apt-get install graphviz
If using macOS, try this brew install graphviz
i) If on windows install it by conda conda install graphviz and add path env variables C:\Users\username\Anaconda3\Library\bin\graphviz
ii) Try to install it via conda install python-graphviz

Related

problem with importing SGDOneClassSVM from sklearn.linear_model

I'm trying "from sklearn.linear_model import SGDOneClassSVM"
but it doesn't work and raises an import error "ImportError: cannot import name 'SGDOneClassSVM' from 'sklearn.linear_model"
Upgrade sklearn package using the command:
pip install --upgrade scikit-learn

Detectron MetadaCatalog and DatasetCatalog import Failed

I'm trying the include of Detectron2.data on Google Colab. I made the connection for colab & my drive. And after that:
!pip install pyyaml
!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.7/index.html
It worked without any error.
i have been trying this;
import numpy as np
import os, json, cv2, random
from google.colab.patches import cv2_imshow
import detectron2
from detectron2.data import MetadataCatalog, DatasetCatalog
from detectron2.utils.visualizer import Visualizer
from detectron2 import model_zoo
But the outputs like this:
enter image description here
How can i fix that?
I fixed like this:
!pip install pyyaml==5.1
import torch, torchvision
print(torch.__version__, torch.cuda.is_available())
!gcc --version
import torch
assert torch.__version__.startswith("1.8")
!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.8/index.html
# exit(0) # After installation, you need to "restart runtime" in Colab. This line can also restart runtime
from: https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5#scrollTo=ZyAvNCJMmvFF

ModuleNotFoundError: No module named 'sksurv' in python

I am trying to run survival analysis in python (pycharm) in linux, here is a part of the code
import numpy as np
import matplotlib.pyplot as plt
#matplotlib inline
import pandas as pd
from sklearn.impute import SimpleImputer
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import train_test_split
from sksurv.datasets import load_flchain
from sksurv.linear_model import CoxPHSurvivalAnalysis
I get the error "ModuleNotFoundError: No module named 'sksurv'", I tried everything, but nothing works.
The required dependencies for scikit-survival,
cvxpy
cvxopt
joblib
numexpr
numpy 1.12 or later
osqp
pandas 0.21 or later
scikit-learn 0.22
scipy 1.0 or later
...will be automatically installed by pip when you run:
pip install scikit-survival
However, one module in particular, osqp, has CMake as one of its dependencies. If you don't have CMake installed, pip install scikit-survival will throw an error and the installation will fail.
You can download CMake for your OS at cmake.org/download
After CMake has installed, you should be able to successfully run
pip install scikit-survival
Notes:
GCC needs to be installed also
scikit-survival works with Python 3.5 or higher
More information is available in the docs

Import error: No module name sklearn.external.six

I am currently using anaconda 4.8.3 and want to display a figure of decision tree and i have install graphviz and pydotplus library in anaconda instead of this i am getting error 'ModuleNotFoundError: No module named 'sklearn.externals.six' .this is my code:
from sklearn.tree import DecisionTreeClassifier
from IPython.display import Image
from sklearn.externals.six import StringIO
from sklearn.tree import export_graphviz
import pydot
features = list(df.columns[1:])
features
This is my error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-19-0b3416ce7fda> in <module>
1 from IPython.display import Image
---> 2 from sklearn.externals.six import StringIO
3 from sklearn.tree import export_graphviz
4 import pydot
5 ModuleNotFoundError: No module named 'sklearn.externals.six'
You can import StringIO from module six directly, no need to downgrade scikit.
from six import StringIO
Module sklearn.externals.six was removed in the scikit-learn version 0.23. To use it you have to downgrade to version 0.22. For that, you can do -
In jupyter notebook try :!pip install --upgrade scikit-learn==0.22
In terminal: pip install --upgrade scikit-learn==0.22

ImportError: cannot import name __check_build

from sklearn import svm
ImportError: cannot import name __check_build
I've been able to install scikit-learn on a fresh virtualenv here but it seems you need to do some extra job to get it up-and-running:
By doing just pip install scikit-learn and then from sklearn import svm you'll get import errors, it seems the library requires numpy and scipy. So you need to do:
pip install numpy scipy
After that it should work fine.

Categories

Resources