hackerrank's People
hackerrank's Issues
housePrice code
remove(list=ls())
xnam <- paste("x", 1:25, sep="")
(fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+"))))
set.seed(20)
data<-read.table("officePriceData.txt", header = FALSE, fill = TRUE)
nFeatures<-data[1][1,] #data$V1[1]
nTrain<-data[2][1,] #data$V2[1]
nTest<-data[1][nTrain+2,] #data$V1[nTrain+2]
trimTrain<-c(1,2+nTrain:length(data$V1))
trimTrain<-c(1,2+nTrain:length(data[[1]]))
trainData<-data[-trimTrain,]
trimTest<-c(1:(2+nTrain))
testData<-data[-trimTest,]
paste1<-paste("trainData$V", 1:nFeatures, sep="",collapse= ",")
degree<-4
paste2<-paste("trainData$V",nFeatures+1,"~ poly(",paste1,",degree = ",degree,",raw = TRUE)", collapse = ",",sep = "")
fmla <- as.formula(paste2)
lmModelDegree4<-lm(trainData$V3~poly(trainData$V1,trainData$V2,degree = 4,raw = TRUE))
lm4<-lm(V3~V1+V2,data=trainData)
lmModelDegree3<-lm(trainData$V3poly(trainData$V1,trainData$V2,degree = 3,raw = TRUE))poly(trainData$V1,trainData$V2,degree = 2,raw = TRUE))
lmModelDegree2<-lm(trainData$V3
lmModelDegree1<-lm(trainData$V3~poly(trainData$V1,trainData$V2,degree = 1,raw = TRUE))
predictedValues<-vector(,length(testData[[1]]))
for (i in 1:length(predictedValues)){
#newdata<-data.frame(chargeTime<-newdata1$chargeTime[i])
newdata<-testData[i,]
pre<-predict(lmModelDegree4,newdata=newdata)
pre
}
laptop
indata <- read.table(file("stdin"), header=F, fill=T)
cat(outputdata)
n <- as.numeric(readLines(file("stdin")))
laptop <- read.table("trainingdata.txt",header = FALSE,sep = ",")
names(laptop)[1]<-"chargeTime"
names(laptop)[2]<-"batteryLife"
maxBatteryLife<-max(laptop$batteryLife)
chargeTime<-laptop$chargeTime[laptop$batteryLife<maxBatteryLife]
batteryLife<-laptop$batteryLife[laptop$batteryLife<maxBatteryLife]
chargeTime <- as.numeric(readLines(file("stdin")))
lmModel<-lm(batteryLife~chargeTime)
newdata1<-data.frame(chargeTime<-chargeTime)
newdata1<-data.frame(chargeTime=chargeTime)
boundaryValue<-min(laptop$chargeTime[laptop$batteryLife==maxBatteryLife])
predictedValues<-vector(,length(chargeTime))
for (i in 1:length(newdata1$chargeTime) ){
if (newdata1$chargeTime[i]<boundaryValue){
#newdata<-data.frame(chargeTime<-newdata1$chargeTime[i])
newdata<-data.frame(chargeTime=newdata1$chargeTime[i])
pre<-predict(lmModel,newdata=newdata$chargeTime)
predictedValues[i]<-pre
for (value in pre) {
if (pre>8){
pre=8
predictedValues[i]<-pre
}
}
}
else {
pre<-maxBatteryLife
predictedValues[i]<-pre
}
}
cat(predictedValues)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.