Explain about initialize() function in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

Explain about initialize() function in R?

Explain about initialize() function in R?

This recipe explains what about initialize() function in R

0

Recipe Objective

When we declare an object in R, the object can be classified either as public data element or private data element. Initialise is a function used to initialise a variable in the form of private data element ​

This recipe demonstrates how to initilise any values to the objects at the time of declaration of the objects. ​

STEP 1: Creating a user defined class

We do that by inclusisng public and private data members ​

library(R6) football <- R6Class( "Football", private = list( name_of_player = NA, goals_scored = NA), public = list( initialize = function(x,y){ private$name_of_player <-x private$goals_scored <-y }) )

The above code means that we trying to initialise the values of "name_of_player" and "goals_scored" during the time of execution/declaration ​

STEP 2: Calling the function and initialising the values to objects

man_utd <- football$new("Paul Pogba", 11) man_utd

  Public:
    clone: function (deep = FALSE) 
    initialize: function (x, y) 
  Private:
    goals_scored: 11
    name_of_player: Paul Pogba

This means that we have succeeded in initialzing the values "Paul Pogba" to name_of_player and "11" to goals_scored. ​

Relevant Projects

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.