<reponame>YantingWan/cloudmesh-analytics
import os
from flask import jsonify, current_app
import numpy as np
from sklearn.linear_model import LinearRegression
from werkzeug.utils import secure_filename
from cloudmesh.file_helpers import *

def linear_regression(file_name, body):
    """
    Linear regression operation on two dimension data. The input format should be a list of pairs, e.g. [[1, 2], [3, 4]...]
    :param file_name: the data source
    :param body: the request body
    :return:
    """
    # Extract parameters from the request body
    paras = body['paras']
    #TODO: Data format is not correct
    try:
        data = read_csv(file_name)
        X = data[:,0]
        Y = data[:,1]
        reg = LinearRegression(**paras).fit(X,Y)
        return jsonify({'coefficient':reg.coef_ })
    except Exception as e:
        return jsonify({'error_message': str(e)})

def pca():
    return jsonify({"output": 'run_pca_success'})


import os
from flask import jsonify, current_app
import numpy as np
from sklearn.linear_model import LinearRegression
from werkzeug.utils import secure_filename
from cloudmesh.file_helpers import *

def linear_regression(file_name, body):
    """
    Linear regression operation on two dimension data. The input format should be a list of pairs, e.g. [[1, 2], [3, 4]...]
    :param file_name: the data source
    :param body: the request body
    :return:
    """
    # Extract parameters from the request body
    paras = body['paras']
    #TODO: Data format is not correct
    try:
        data = read_csv(file_name)
        X = data[:,0]
        Y = data[:,1]
        reg = LinearRegression(**paras).fit(X,Y)
        return jsonify({'coefficient':reg.coef_ })
    except Exception as e:
        return jsonify({'error_message': str(e)})

def pca():
    return jsonify({"output": 'run_pca_success'})
Linear regression operation on two dimension data. The input format should be a list of pairs, e.g. [[1, 2], [3, 4]...]     :param file_name: the data source     :param body: the request body     :return: # Extract parameters from the request body #TODO: Data format is not correct