ModuleNotFoundError No module named 'scikit_keras' - tensorflow

i cant figure aou where im doing wrong,`
from sklearn.neural_network import MLPRegressor
from sklearn.preprocessing import RobustScaler
import pandas as pd
import yfinance as yf
import numpy as np
from sklearn.metrics import mean_squared_error, r2_score, mean_absolute_error, median_absolute_error
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
import matplotlib.pyplot as plt
from sklearn.model_selection import TimeSeriesSplit, StratifiedKFold, KFold, train_test_split, cross_val_score, GridSearchCV, ShuffleSplit
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
from scikit_keras import KerasClassifier
i installed all the packages using pip command and also as suggested in other post i used
pip install patchify
but still get error
xception has occurred: ModuleNotFoundError No module named 'scikit_keras'
next i give a list of all package version
Name: scikit-learn Version: 1.2.0 Name: pandas Version: 1.5.2 Name: yfinance Version: 0.1.90 Name: numpy Version: 1.23.5 Name: tensorflow Version: 2.11.0 Name: keras Version: 2.11.0

It looks like you installed scikit-keras which implements a KerasClassifier.
Which means the last line should be:
from skkeras import KerasClassifier

Related

sklearn, xgboost ModuleNotFoundError

pip install -q hvplot
import pandas as pd
import numpy as np
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
import hvplot.pandas
from sklearn.model_selection import train_test_split, RandomizedSearchCV
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import (
accuracy_score, confusion_matrix, classification_report,
roc_auc_score, roc_curve, auc,
plot_confusion_matrix, plot_roc_curve
)
from xgboost import XGBClassifier
from sklearn.ensemble import RandomForestClassifier
import tensorflow as tf
from tensorflow.keras.models import Sequential, Model
from tensorflow.keras.layers import Dense, Dropout, BatchNormalization
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import AUC
pd.set_option('display.float', '{:.2f}'.format)
pd.set_option('display.max_columns', 50)
pd.set_option('display.max_rows', 50)
I'm trying to run a code from Kaggle.
https://www.kaggle.com/code/faressayah/lending-club-loan-defaulters-prediction
However, I was stuck in the first few steps, which are the code lines above. I've spent hours on this and can't figure it out. I got the following error message
Does anyone know how to fix this? Thank you very much for helping out!

AttributeError: module 'tensorflow.compat.v2.tpu.experimental' has no attribute 'HardwareFeature'

Running below code gave the error as AttributeError: module 'tensorflow.compat.v2.tpu.experimental' has no attribute 'HardwareFeature'
import os
import pprint
import tempfile
from typing import Dict, Text
import numpy as np
import pandas as pd
import tensorflow as tf
import tensorflow_datasets as tfds
!pip install -q tensorflow-recommenders
import tensorflow_recommenders as tfrs
tensorflow version used was 2.9.1 and the code was run from Google Colab
Did a trial and error changed the order of execution as below and it worked fine no errors this time
!pip install -q tensorflow-recommenders
import os
import pprint
import tempfile
from typing import Dict, Text
import numpy as np
import pandas as pd
import tensorflow as tf
import tensorflow_datasets as tfds
import tensorflow_recommenders as tfrs

Unable to Import Efficientnet in Colab

I am working in colab to test a code. While importing models, its giving error No module named 'efficientnet'
I am sharing the code and error here.
# for accessing tabular data
import pandas as pd
import numpy as np
import os
os.chdir('/content/drive/My Drive/')
# adding classweight
from sklearn.utils import class_weight
# Evaluation Metric
from sklearn.metrics import cohen_kappa_score
from sklearn.metrics import confusion_matrix, precision_score, recall_score
# for visualization
import cv2
import matplotlib.pyplot as plt
import seaborn as sns
from prettytable import PrettyTable
# backend
import keras
from keras import backend as K
import tensorflow as tf
from keras.callbacks import Callback
# for transfer learning
from tensorflow.keras.applications import VGG16, VGG19
from tensorflow.keras.applications import DenseNet121
from tensorflow.keras.applications import ResNet50, ResNet152
from tensorflow.keras.applications import InceptionV3
from efficientnet.keras import EfficientNetB0, EfficientNetB3, EfficientNetB4
from keras.applications import Xception
# for model architecture
from keras.models import Sequential
from keras.layers import GlobalAveragePooling2D, Dropout, Dense, Conv2D, MaxPooling2D, Activation, Flatten
# for Tensorboard visualization
from keras.callbacks import TensorBoard
# for Data Augmentation
from keras.preprocessing.image import ImageDataGenerator
enter image description here
It should be,
from tensorflow.keras.applications import EfficientNetB0, EfficientNetB3, EfficientNetB4

cannot import name 'PlotLossesTensorFlowKeras' in jupyter notebook even though I have installed all dependencies

This problem appears on my jupyter notebook.
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import utils
import os
%matplotlib inline
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D
#from keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Dense, Input, Dropout,Flatten
from tensorflow.keras.layers import BatchNormalization, Activation, MaxPooling2D
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau
from tensorflow.keras.utils import plot_model
from tensorflow.keras.models import Sequential
from IPython.display import SVG, Image
from livelossplot import PlotLossesTensorFlowKeras
import tensorflow as tf
print("Tensorflow version:", tf.__version__)
I have tried pip install livelossplot but no use.
Any help is appreciated
I also faced the same issue then what I did which worked for me is, replace that with this code:
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import utils
import os
%matplotlib inline
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Dense, Input, Dropout,Flatten, Conv2D
from tensorflow.keras.layers import BatchNormalization, Activation, MaxPooling2D
from tensorflow.keras.models import Model, Sequential
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau
from tensorflow.keras.utils import plot_model
from IPython.display import SVG, Image
#from livelossplot import PlotLossesTensorFlowKeras
from livelossplot import PlotLossesKeras
from livelossplot.keras import PlotLossesCallback
import tensorflow as tf
print("Tensorflow version:", tf.__version__)
You may now proceed further.
I think we followed the same tutorial in coursera.
The problem is a version mismatch
pip uninstall livelossplot
pip install livelossplot==0.5.2
Then use this
from livelossplot import PlotLossesKeras
instead of the old one.

Unable to open file mnist.h5

I am working on a project that detects handwritten characters. There are many packages I have imported. One of the package keras.models.load_model(mnist.h5) is throwing following error:
OSError: Unable to open file (unable to open file: name = 'mnist.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
Code Snippet is:
from keras.models import load_model
from tkinter import *
import tkinter as tk
import win32gui
from PIL import ImageGrab, Image
import numpy as np
model = load_model('mnist.h5')
Using Python 3.7
Can anyone please help me.
Thank you
Please refer working code to import the Mnist data set.
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
print(tf.__version__)
#### Import the Fashion MNIST dataset
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()