You are given the daily temperature reading of P towns and the daily temperature reading of New York City (NYC) for N days. For the given data, write a function that returns a set of five towns that are jointly as predictive as possible of the daily temperate of NYC. Note that the exact solution to this problem requires an exhaustive search that can be computationally challenging. We expect you to write an approximate solution that is as fast, or maybe faster, than your solution to Question 2.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

ANSWER MUST BE IN PYTHON3. METHOD HEADER BELOW.

 

#!/bin/python3

import math
import os
import random
import re
import sys
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression

def read_dataframe():
    # Return a pandas dataframe from stdin
    return pd.read_csv(sys.stdin)

def read_matrix():
    # Return column names and data as a matrix
    df = read_dataframe()
    return list(df.columns), df.values

def read_list():
    # Return column names and data as a list of lists
    # Each element in the list corresponds to columns in the data
    col_names, val = read_matrix()
    return col_names, val.T.tolist()

#
# Complete the 'main' function below.
#
# The function is expected to return a STRING.
#

def main():
    # Write your code here

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    result = main()

    fptr.write(result + '\n')

    fptr.close()
Question 3 is a bonus question and will not be scored. The parameters and data set remain the same from Question 2. Please
finish Questions 1 and 2 before attempting Question 3.
You are given the daily temperature reading of P towns and the daily temperature reading of New York City (NYC) for N days.
For the given data, write a function that returns a set of five towns that are jointly as predictive as possible of the
daily temperate of NYC. Note that the exact solution to this problem requires an exhaustive search that can be computationally
challenging. We expect you to write an approximate solution that is as fast, or maybe faster, than your solution to Question 2.
Function Description
Complete the function main() to read the data from stdin and answer the question. The input data is in CSV format with a
header row indicating the town names; use this header rather than making assumptions about column order. Depending on
the language you choose we may provide boilerplate code for reading the data - you are welcome to use this if you wish. You
are also welcome to import packages (such as sklearn in Python), as long as they are available in the HackerRank environment.
The function main should return a string with the name of the five towns. For example, a valid output is
"Town1,Town2,Town3,Town4,Town5". We will use the name of the towns you provide to compute the R² for each test case.
Constraints
• N>5 and 4 < P < 60
▼ Input Format For Custom Testing
The first line contains a comma separated list of strings corresponding to the name of the towns.
Each subsequent line contains comma separated values corresponding to the temperature of each town.
Example:
Town1, Town2, Town3, Town4, Town5, Town6, NYC
34,32,53,5,10,29,40
86,91,24,10,12,50,45
56,78,90,23,23, 45, 23
23,92,45,44, 55, 67,34
12,99,23,34,64,56,35
22,102,11, 23, 45, 65,43
Transcribed Image Text:Question 3 is a bonus question and will not be scored. The parameters and data set remain the same from Question 2. Please finish Questions 1 and 2 before attempting Question 3. You are given the daily temperature reading of P towns and the daily temperature reading of New York City (NYC) for N days. For the given data, write a function that returns a set of five towns that are jointly as predictive as possible of the daily temperate of NYC. Note that the exact solution to this problem requires an exhaustive search that can be computationally challenging. We expect you to write an approximate solution that is as fast, or maybe faster, than your solution to Question 2. Function Description Complete the function main() to read the data from stdin and answer the question. The input data is in CSV format with a header row indicating the town names; use this header rather than making assumptions about column order. Depending on the language you choose we may provide boilerplate code for reading the data - you are welcome to use this if you wish. You are also welcome to import packages (such as sklearn in Python), as long as they are available in the HackerRank environment. The function main should return a string with the name of the five towns. For example, a valid output is "Town1,Town2,Town3,Town4,Town5". We will use the name of the towns you provide to compute the R² for each test case. Constraints • N>5 and 4 < P < 60 ▼ Input Format For Custom Testing The first line contains a comma separated list of strings corresponding to the name of the towns. Each subsequent line contains comma separated values corresponding to the temperature of each town. Example: Town1, Town2, Town3, Town4, Town5, Town6, NYC 34,32,53,5,10,29,40 86,91,24,10,12,50,45 56,78,90,23,23, 45, 23 23,92,45,44, 55, 67,34 12,99,23,34,64,56,35 22,102,11, 23, 45, 65,43
1v#!/bin/python3
OUолашин
2
3
4
5
6
7
8
9
10
11
12
N
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import math
import os
import random
import re
import sys
import numpy as np
import pandas as pd
from sklearn.linear_model import Linear Regression
def read_dataframe():
def read_matrix():
# Return column names and data as a matrix
df = read_dataframe()
return list (df.columns), df.values
# Return a pandas dataframe from stdin
return pd. read_csv (sys.stdin)
def read_list():
# Return column names and data as a list of lists
# Each element in the list corresponds to columns in the data
col_names, val = read_matrix()
return col_names, val.T.tolist()
|
#
# Complete the 'main' function below.
#
# The function is expected to return a STRING.
#
32
33
34
35
ww
36 if __name_
def main():
# Write your code here
__main__': ...
Transcribed Image Text:1v#!/bin/python3 OUолашин 2 3 4 5 6 7 8 9 10 11 12 N 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import math import os import random import re import sys import numpy as np import pandas as pd from sklearn.linear_model import Linear Regression def read_dataframe(): def read_matrix(): # Return column names and data as a matrix df = read_dataframe() return list (df.columns), df.values # Return a pandas dataframe from stdin return pd. read_csv (sys.stdin) def read_list(): # Return column names and data as a list of lists # Each element in the list corresponds to columns in the data col_names, val = read_matrix() return col_names, val.T.tolist() | # # Complete the 'main' function below. # # The function is expected to return a STRING. # 32 33 34 35 ww 36 if __name_ def main(): # Write your code here __main__': ...
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Linear Programming Concepts
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education