def upload_file(): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: return "Incomplete Request" file = request.files['file'] print(file) file.filename = request.form['name'].replace(".", "") + '.py' # if user does not select file, browser also # submit an empty part without filename if file.filename == '': return 'No selected file' scores = 1 if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(UPLOAD_FOLDER[:2], filename)) try: nen = {i:globals()[i] for i in globals()} exec('from ' + filename[:-3] + ' import *', globals()) print("executing...", "[", request.form['name'], "]") nan = {i:globals()[i] for i in globals()} non = set(nan) - set(nen) for i in non: print(["importing..."], i, globals()[i]) score = {} tests = os.listdir(UPLOAD_FOLDER) print(12) for i in tests: if allowed_file(i): print(i) score[i] = str(otter.Notebook(UPLOAD_FOLDER[2:]).check(i.split('.')[0])) print(13) files = [] for i in score: print(i) print(score[i]) if 'All tests passed!' in score[i]: files.append(i) scores = 0 for i in files: print(i) with open(UPLOAD_FOLDER + '/' + i) as f: a = f.read() if '"points":' in a: b = a.split('\n')[2] c = b.split(":")[1] d = c.replace(",", "") scores += int(d) print(d) exec('import ' + filename[:-3] + ' as ma', globals()) for name, data in inspect.getmembers(ma): if name.startswith('_'): continue if name in globals(): print(["2"], name, ['deleting...']) del globals()[name] if ma in globals(): del globals()[ma] for i in globals(): if str(i) in non and str(i) not in nen: print(["2"], i, ["deleting..."]) del globals()[i] with open(os.path.join(UPLOAD_FOLDER[:2], filename), "r") as f: s = f.read() if "import" in s: return jsonify({"name":request.form['name'], "score":-15}) print(s) f.close() os.remove(os.path.join(UPLOAD_FOLDER[:2], filename)) if scores == 0: scores = 1 return jsonify({"name":request.form['name'], "score":scores}) except Exception as e: exec('import ' + filename[:-3] + ' as ma', globals()) for name, data in inspect.getmembers(ma): if name.startswith('_'): continue if name in globals(): print(name, ['deleting...']) del globals()[name] if ma in globals(): del globals()[ma] for i in globals(): if str(i) in non and str(i) not in nen: print(["2"], i, ["deleting..."]) del globals()[i] with open(os.path.join(UPLOAD_FOLDER[:2], filename), "r") as f: s = f.read() if "import" in s: return jsonify({"name":request.form['name'], "score":-15}) print(s) f.close() os.remove(os.path.join(UPLOAD_FOLDER[:2], filename)) print(e) scores = 1 return jsonify({"name":request.form['name'], "score":scores}) return "Oops! an error occured." return '''
On the Cluster data, perform a 50/50 train test split with `random state` equal to 99. Predict `y` with all variables using regression analysis. 3a. Calculate the r2 for train and assign to `cluster1_r2_train`. 3b. calculate the r2 for test and assign to `cluster1_r2_test`. ### KMeans Cluster Analysis Next perform a cluster analysis using ONLY variables that start with `cad0`-`cad9` and specify 6 clusters. Set random_state to `99` for KMEANS algorithm. Add the variable `df_cluster['cluster']` to the origional dataframe to indicate the cluster membership. ### 4. Clusters Continued Then select only rows from df_clusterwhich you have assigned to cluster 1. For only cluster 1 predict `y` with all variables using regression analysis. 4a. Calculate the r2 for train and assign to `cluster2_r2_train`. 4b. calculate the r2 for test and assign to `cluster2_r2_test`. Like before set random_state to `99`. #This runs all tests. import otter grader = otter.Notebook() grader.check_all()
#!/usr/bin/env python # coding: utf-8 # In[1]: import matplotlib.pyplot as plt import numpy as np # get_ipython().run_line_magic('matplotlib', 'inline') import otter grader = otter.Notebook("../tests") # **Question 1:** Write a function `square` that squares its argument. # In[2]: def square(x): return x**3 # In[3]: grader.check("q1") # **Question 2:** Write a function `negate` that negates its argument. # In[4]: