# Load required libraries
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(boot)
##
## Attaching package: 'boot'
## The following object is masked from 'package:lattice':
##
## melanoma
library(caretEnsemble)
## Warning: package 'caretEnsemble' was built under R version 4.3.2
##
## Attaching package: 'caretEnsemble'
## The following object is masked from 'package:ggplot2':
##
## autoplot
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(readr)
properties_dataset <- read_csv("data/properties.csv")
## New names:
## Rows: 12685 Columns: 145
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (38): Possession Status, Availability Starts From, Floor No, Commercial... dbl
## (105): ID, Units Available, Price, Maintenance Charges, Booking Amount, ... num
## (1): Covered Area...40 lgl (1): Luxury Flat
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `Covered Area` -> `Covered Area...17`
## • `Parking` -> `Parking...28`
## • `Covered Area` -> `Covered Area...40`
## • `Parking` -> `Parking...58`
# Load data from a CSV file
library(readr)
properties <- read_csv("data/properties.csv")
## New names:
## Rows: 12685 Columns: 145
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (38): Possession Status, Availability Starts From, Floor No, Commercial... dbl
## (105): ID, Units Available, Price, Maintenance Charges, Booking Amount, ... num
## (1): Covered Area...40 lgl (1): Luxury Flat
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `Covered Area` -> `Covered Area...17`
## • `Parking` -> `Parking...28`
## • `Covered Area` -> `Covered Area...40`
## • `Parking` -> `Parking...58`
View(properties)
View(properties)
# Load required libraries
library(caret)
# Assuming your target variable is named 'Price' and predictors are in 'properties_dataset'
# Adjust these based on your actual dataset
# Data Splitting
# Load required libraries
library(caret)
# Assuming your target variable is named 'Price' and predictors are in 'properties_dataset'
# Adjust these based on your actual dataset
# Check for missing values in the 'Price' column
if (any(is.na(properties_dataset$Price))) {
print("Error: Missing values found in the 'Price' column. Handle missing values before proceeding.")
} else {
# Data Splitting
set.seed(123) # for reproducibility
splitIndex <- createDataPartition(properties_dataset$Price, p = 0.7, list = FALSE)
# Check if splitIndex is not empty
if (length(splitIndex) > 0) {
train_data <- properties_dataset[splitIndex, ]
test_data <- properties_dataset[-splitIndex, ]
# Continue with the rest of your analysis using train_data and test_data
} else {
print("Error: Not enough data points for splitting.")
}
}
## [1] "Error: Missing values found in the 'Price' column. Handle missing values before proceeding."
You can also embed plots, for example:
library(readr)
properties_dataset <- read_csv("data/properties.csv")
## New names:
## Rows: 12685 Columns: 145
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (38): Possession Status, Availability Starts From, Floor No, Commercial... dbl
## (105): ID, Units Available, Price, Maintenance Charges, Booking Amount, ... num
## (1): Covered Area...40 lgl (1): Luxury Flat
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `Covered Area` -> `Covered Area...17`
## • `Parking` -> `Parking...28`
## • `Covered Area` -> `Covered Area...40`
## • `Parking` -> `Parking...58`
# Load data from a CSV file
library(readr)
properties <- read_csv("data/properties.csv")
## New names:
## Rows: 12685 Columns: 145
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (38): Possession Status, Availability Starts From, Floor No, Commercial... dbl
## (105): ID, Units Available, Price, Maintenance Charges, Booking Amount, ... num
## (1): Covered Area...40 lgl (1): Luxury Flat
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `Covered Area` -> `Covered Area...17`
## • `Parking` -> `Parking...28`
## • `Covered Area` -> `Covered Area...40`
## • `Parking` -> `Parking...58`
View(properties)
View(properties)
# Data Splitting
# Load required libraries
library(caret)
# Assuming your target variable is named 'Price' and predictors are in 'properties_dataset'
# Adjust these based on your actual dataset
# Check for missing values in the 'Price' column
if (any(is.na(properties_dataset$Price))) {
print("Error: Missing values found in the 'Price' column. Handle missing values before proceeding.")
} else {
# Data Splitting
set.seed(123) # for reproducibility
splitIndex <- createDataPartition(properties_dataset$Price, p = 0.7, list = FALSE)
# Check if splitIndex is not empty
if (length(splitIndex) > 0) {
train_data <- properties_dataset[splitIndex, ]
test_data <- properties_dataset[-splitIndex, ]
# Continue with the rest of your analysis using train_data and test_data
} else {
print("Error: Not enough data points for splitting.")
}
}
## [1] "Error: Missing values found in the 'Price' column. Handle missing values before proceeding."
You can also embed plots, for example:
library(readr)
properties_dataset <- read_csv("data/properties.csv")
## New names:
## Rows: 12685 Columns: 145
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (38): Possession Status, Availability Starts From, Floor No, Commercial... dbl
## (105): ID, Units Available, Price, Maintenance Charges, Booking Amount, ... num
## (1): Covered Area...40 lgl (1): Luxury Flat
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `Covered Area` -> `Covered Area...17`
## • `Parking` -> `Parking...28`
## • `Covered Area` -> `Covered Area...40`
## • `Parking` -> `Parking...58`
# Load data from a CSV file
library(readr)
properties <- read_csv("data/properties.csv")
## New names:
## Rows: 12685 Columns: 145
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (38): Possession Status, Availability Starts From, Floor No, Commercial... dbl
## (105): ID, Units Available, Price, Maintenance Charges, Booking Amount, ... num
## (1): Covered Area...40 lgl (1): Luxury Flat
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `Covered Area` -> `Covered Area...17`
## • `Parking` -> `Parking...28`
## • `Covered Area` -> `Covered Area...40`
## • `Parking` -> `Parking...58`
View(properties)
View(properties)
# Load required libraries
library(caret)
library(e1071) # Example: SVM, replace with the appropriate modeling package
# Assuming 'Price' is the target variable
target_var <- 'Price'
# Assuming 'properties_dataset' is your dataset
data <- properties_dataset
# Check for missing values in the target variable
if (any(is.na(data[, target_var]))) {
print("Error: Missing values found in the target variable. Handle missing values before proceeding.")
} else {
# Data Splitting
set.seed(123) # for reproducibility
splitIndex <- createDataPartition(data[, target_var], p = 0.7, list = FALSE)
# Check if splitIndex is not empty
if (length(splitIndex) > 0) {
train_data <- data[splitIndex, ]
test_data <- data[-splitIndex, ]
# Bootstrapping (Example: Random Forest)
set.seed(123)
boot_model <- train(Price ~ ., data = train_data, method = "rf", trControl = trainControl(method = "boot", number = 50))
# Cross-validation (Example: Support Vector Machine)
set.seed(123)
cv_model <- train(Price ~ ., data = train_data, method = "svmRadial", trControl = trainControl(method = "cv", number = 5))
# Model training for regression (Example: Linear Regression)
set.seed(123)
regression_model <- train(Price ~ ., data = train_data, method = "lm")
# Model performance comparison using resamples
models <- list(boot = boot_model, cv = cv_model, regression = regression_model)
resamples <- resamples(models)
# Summary of resampling results
summary(resamples)
} else {
print("Error: Not enough data points for splitting.")
}
}
## [1] "Error: Missing values found in the target variable. Handle missing values before proceeding."
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.