from ffnet import ffnet,mlgraph,tmlgraph
import numpy as np

class neuralnetwork:
    def __init__(self, shape, loadnet=None, full_conn=True, biases=False):
        """
        shape: shape of a NN given as a tuple
        """
        if loadnet:
            self.model = ffnet()
            self.model.load(loadnet)
        else:
            if full_conn:
                conec = tmlgraph(shape, biases)
            else:
                conec = mlgraph(shapebiases)
            self.model = ffnet(conec)
    
    def fit(self, input_descriptors, target_values, train_alg='tnc'):
        getattr(self.model, 'train_'+train_alg)(input_descriptors, target_values, maxfun=10000)
    
    def predict(self, input_descriptors):
         return np.array(self.model.call(input_descriptors)).flatten()

from ffnet import ffnet,mlgraph,tmlgraph
import numpy as np
from scipy.stats import linregress

class neuralnetwork:
    def __init__(self, shape, loadnet=None, full_conn=True, biases=False):
        """
        shape: shape of a NN given as a tuple
        """
        if loadnet:
            self.model = ffnet()
            self.model.load(loadnet)
        else:
            if full_conn:
                conec = tmlgraph(shape, biases)
            else:
                conec = mlgraph(shapebiases)
            self.model = ffnet(conec)
    
    def fit(self, input_descriptors, target_values, train_alg='tnc'):
        getattr(self.model, 'train_'+train_alg)(input_descriptors, target_values, maxfun=10000)
    
    def predict(self, input_descriptors):
        return np.array(self.model.call(input_descriptors))
    
    def score(X, y):
        return linregress(self.predict(X), y)[2]**2
        

Add missing methods to NN class
Add missing methods to NN class

  from ffnet import ffnet,mlgraph,tmlgraph
  import numpy as np
+ from scipy.stats import linregress
  
  class neuralnetwork:
      def __init__(self, shape, loadnet=None, full_conn=True, biases=False):
          """
          shape: shape of a NN given as a tuple
          """
          if loadnet:
              self.model = ffnet()
              self.model.load(loadnet)
          else:
              if full_conn:
                  conec = tmlgraph(shape, biases)
              else:
                  conec = mlgraph(shapebiases)
              self.model = ffnet(conec)
      
      def fit(self, input_descriptors, target_values, train_alg='tnc'):
          getattr(self.model, 'train_'+train_alg)(input_descriptors, target_values, maxfun=10000)
      
      def predict(self, input_descriptors):
-          return np.array(self.model.call(input_descriptors)).flatten()
+         return np.array(self.model.call(input_descriptors))
+     
+     def score(X, y):
+         return linregress(self.predict(X), y)[2]**2
+         
  
Add missing methods to NN class
## Code Before:
from ffnet import ffnet,mlgraph,tmlgraph
import numpy as np

class neuralnetwork:
    def __init__(self, shape, loadnet=None, full_conn=True, biases=False):
        """
        shape: shape of a NN given as a tuple
        """
        if loadnet:
            self.model = ffnet()
            self.model.load(loadnet)
        else:
            if full_conn:
                conec = tmlgraph(shape, biases)
            else:
                conec = mlgraph(shapebiases)
            self.model = ffnet(conec)
    
    def fit(self, input_descriptors, target_values, train_alg='tnc'):
        getattr(self.model, 'train_'+train_alg)(input_descriptors, target_values, maxfun=10000)
    
    def predict(self, input_descriptors):
         return np.array(self.model.call(input_descriptors)).flatten()

## Instruction:
Add missing methods to NN class
## Code After:
from ffnet import ffnet,mlgraph,tmlgraph
import numpy as np
from scipy.stats import linregress

class neuralnetwork:
    def __init__(self, shape, loadnet=None, full_conn=True, biases=False):
        """
        shape: shape of a NN given as a tuple
        """
        if loadnet:
            self.model = ffnet()
            self.model.load(loadnet)
        else:
            if full_conn:
                conec = tmlgraph(shape, biases)
            else:
                conec = mlgraph(shapebiases)
            self.model = ffnet(conec)
    
    def fit(self, input_descriptors, target_values, train_alg='tnc'):
        getattr(self.model, 'train_'+train_alg)(input_descriptors, target_values, maxfun=10000)
    
    def predict(self, input_descriptors):
        return np.array(self.model.call(input_descriptors))
    
    def score(X, y):
        return linregress(self.predict(X), y)[2]**2
        
