Artificial Intelligence

Deep Learning with Keras in R | Multilayer Perceptron Neural Network for Multiclass Classification

4Views

Disclaimer

39 Comments

  • Thank you for this nice tutorial.
    When creating the dummy variables using one hot encoding, shouldn't we remove the first column because of the "dummy variable trap"? Correct me if I am wrong but my understanding is that if we have K categories, we need to have K-1 dummy variables.

  • Sir after calling library(keras) do I need to run install_keras() everytime I work on keras? Suppose if I have installed keras and install_keras() today and if i want to again work after a week do I need to again run the code install_keras() or just library(keras). Thank you sir.

  • Thank you for your tutorials.TypeError occured in "fit model" as followTypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("dense_7_input:0", shape=(?, 21), dtype=float32) is not an element of this graph.
    What actions needed?

  • Hi Bharatendra,
    I tried the sample, but I get error when running the FIT command.
    here is my R file – https://drive.google.com/open?id=1_6w-sJR1DxolEKtT8X-4RbKc7UgxF0OW
    The error is – Error in py_call_impl(callable, dots$args, dots$keywords) :
    ValueError: Error when checking input: expected dense_17_input to have shape (None, 21) but got array with shape (21, 1) …
    would you know what's going on…
    I used the same dataset as uploaded by you.
    Please see if you can resolve the issue.

  • hi bharatendra,

    some of the r- packages are not able to install in particular version,
    for example : am not able to install "keras" library in Version 3.1.2
    please solve, how to over come this problem ? in future if suppose am installing other package also ?

    Warning in install.packages :
    package ‘keras’ is not available (for R version 3.1.2)

  • hi bharatendra, Firstly, great video. Two Questions. Q1 Is there any inherent cross-validation specified in the example you run in the video? My my data set is 'relatively small', so I need some kind of C-V. Q2 I have a reasonably high numbers of Missing data points (sparse-data). The data is point-in-time but not a time series. I realise the 'best' approach for handling NA's is data dependent, buy any suggestions how to handle this would be very much appreciated. Alex

  • Can you use neural Networks if you have not one categorical Output like above but lets say 20 Outputs
    how you suggest to use neural network. will it be different neural network for different Output variable ?
    if yes than how you do prediction?

  • Hello sir, I followed the steps as per the video but at the end when I try to run Fit() it throws an error.

    Error in py_call_impl(callable, dots$args, dots$keywords) :
    TypeError: update() takes at most 3 arguments (4 given)

    Tried to resolve it by updating R studio, keras but did not resolve it. Can you please address this issue?

    Thank you!!

  • Hi Sir, great video, I would like to ask can I perform deep learning on a data set which is a mix of categorical and continuous variable where levels of few variables are more than 60 ?
    Also my target variable is a continuous variable.

    Awaiting your response.

    Thank you

  • Sir I have one more request could you make a video to explain these concepts K fold cross validation, boosting and bagging, gradient descent, grid search and other boosting algorithm? I have read a lot but I never understood how it works and how to use it. Thank you Sir.

  • Hi Sir,
    am getting error like
    Error in py_call_impl(callable, dots$args, dots$keywords) :
    ValueError: No data provided for "dense_3_input". Need data for each key in: ['dense_3_input']

  • Sir, I did this above model it worked for me. But after confusion matrix i want to denormalize it, I used traditional formula denormalized = (normalized)*(max(x)-min(x))+min(x) as a function not working? suggest me any other

  • Hey there! Graet work my friend!
    I've been trying to follow your steps with another data frame, but after installing everything, and running i get the same problem each time… I've tried everything, but I can't get it to work 🙁
    I was wondering if you could help me pleeease!
    This are the code lines and the message I get:

    data[,-c(6,19,20)]<-as.numeric(data[,-c(6,19,20)])
    data[,c(6,19,20)]<-as.numeric(data[,c(6,19,20)])
    data[,1:20]<-normalize(data[,1:20])

    Error in py_call_impl(callable, dots$args, dots$keywords) :
    AttributeError: 'str' object has no attribute 'conjugate'

    Detailed traceback:
    File "C:PROGRA~3ANACON~1envsR-TENS~1libsite-packageskerasutilsnp_utils.py", line 48, in normalize
    l2 = np.atleast_1d(np.linalg.norm(x, order, axis))
    File "C:PROGRA~3ANACON~1envsR-TENS~1libsite-packagesnumpylinalglinalg.py", line 2197, in norm
    s = (x.conj() * x).real

    Thanks!

  • I have 5 predicted class and i got this error ,
    Error in py_call_impl(callable, dots$args, dots$keywords) :
    ValueError: Error when checking target: expected dense_12 to have shape (5,) but got array with shape (3,)
    My Code is :

    dataset[,2:31] <- normalize(dataset[,2:31])
    dataset[,1] <- as.numeric(dataset[,1])-1
    set.seed(123)
    ind <- sample(2, nrow(dataset), replace = T, prob = c(0.8,0.2))
    training <- dataset[ind == 1, 2:31]
    test <- dataset[ind == 2, 2:31]
    traintarget <- dataset[ind == 1, 1]
    testtarget <- dataset[ind == 2, 1]

    trainLabel <- to_categorical(traintarget)
    testLabel <- to_categorical(testtarget)

    model <- keras_model_sequential()
    model %>%
    layer_dense(units = 8, activation = 'relu', input_shape = c(30)) %>%
    layer_dense(units = 5, activation = 'softmax')

    model %>%
    compile(loss = 'categorical_crossentropy',
    optimizer = 'adam',
    metrics = 'accuracy')

    history <- model %>%
    fit(training,
    trainLabel,
    epochs = 200,
    batch_size = 32,
    validation_split = 0.2)

  • Hi Sir! i keep getting this error whenever i try to use any function of the keras package. i followed the video from beginning.
    Please help 🙁
    for example-data[, 1:7] <- normalize(data[,1:7])
    Using TensorFlow backend.
    Error: ImportError: Traceback (most recent call last):
    File "C:ANACON~1envsR-TENS~1libsite-packagestensorflowpythonpywrap_tensorflow_internal.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
    File "C:ANACON~1envsR-TENS~1libimportlib__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
    File "<frozen importlib._bootstrap>", line 571, in module_from_spec
    File "<frozen importlib._bootstrap_external>", line 922, in create_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

    During handling of the

    PS-in order to resolve the above error i have installed python 3.6 and its corresponding anaconda version and also i tried installing tensorflow using anaconda in python but it showed error,went through lots of videos still getting the same above error

  • If there is a class imbalance how does one handle that in keras (similiar to the video you did for machine learning


    ? Thank you.

  • > Hi Sir ,
    stuck with the error unable to poceed

    install.packages("keras")
    Installing package into ‘C:/Users/Apricot/Documents/R/win-library/3.1’
    (as ‘lib’ is unspecified)
    Warning in install.packages :
    package ‘keras’ is not available (as a binary package for R version 3.1.3)
    > library(keras)
    Error in library(keras) : there is no package called ‘keras’
    > install_keras()
    Error: could not find function "install_keras"

Leave a Reply