简体   繁体   English

Deeplearning4j预测二手车价格

[英]Deeplearning4j predicting used cars prices

I want to predict prices for used cars and I have historical data of sold cars. 我想预测二手车的价格,我有二手车的历史数据。 I scaled numeric values into 0-1 and made other features one hot. 我将数值缩放为0-1,并将其他功能设为热门。

数据:

public RestResponse<JSONObject> buildModelDl4j( HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> json ) throws IOException
{
    RestResponse<JSONObject> restResponse = ControllerBase.getRestResponse( request, response, null ) ;

    String path = "\\HOME_EXCHANGE\\uploads\\" + json.get( "filePath" ) ;

    int numLinesToSkip = 1 ;
    char delimiter = ',' ;

    RecordReader recordReader = new CSVRecordReader( numLinesToSkip, delimiter ) ;

    try
    {
        recordReader.initialize( new FileSplit( new File( path ) ) ) ;
    }
    catch( InterruptedException e )
    {
        e.printStackTrace( ) ;
    }

    DataSetIterator iter = new RecordReaderDataSetIterator( recordReader, batchSize, indexToCalc, indexToCalc, true ) ;
    json.put( "numAttr", String.valueOf( numAttr ) ) ;

    //        ds.shuffle( ) ;   //TODO should I shuffle the data ?

    MultiLayerNetwork net = buildNetwork( json ) ;

    net.init( ) ;

    net.setListeners( new ScoreIterationListener( 30 ) ) ;

    DataSet testData = null ;

    for( int i = 0; i < nEpochs; i++ )
    {
        iter.reset( ) ;

        while( iter.hasNext( ) )
        {
            DataSet ds = iter.next( ) ;
            SplitTestAndTrain testAndTrain = ds.splitTestAndTrain( splitRate / 100.0 ) ;
            DataSet trainingData = testAndTrain.getTrain( ) ;
            testData = testAndTrain.getTest( ) ;
            net.fit( trainingData ) ;
        }

        iter.reset( ) ;

        int cnt = 0 ;
        while( iter.hasNext( ) && cnt++ < 3 )
        {
            DataSet ds = iter.next( ) ;
            SplitTestAndTrain testAndTrain = ds.splitTestAndTrain( splitRate / 100.0 ) ;
            testData = testAndTrain.getTest( ) ;
            String testResults = testResults( net, testData, indexToCalc ) ;
            System.err.println( "Test results:  [" + i + "]  \n" + testResults ) ;
        }

    }

    RegressionEvaluation eval = new RegressionEvaluation( ) ;
    INDArray output = net.output( testData.getFeatures( ) ) ;
    eval.eval( testData.getLabels( ), output ) ;
    System.out.println( eval.stats( ) ) ;

    String testResults = testResults( net, testData, indexToCalc ) ;

    result.put( "testResults", testResults ) ;

    System.err.println( "Test results last: \n" + testResults ) ;

    restResponse.setData( result ) ;

    return restResponse ;
}

I build model with parameters passed from front-end, I read data from csv files then train the model. 我使用从前端传递的参数构建模型,我从csv文件中读取数据,然后训练模型。 Am I doing the right thing? 我做对了吗? How should I use test and train data? 我应该如何使用测试和训练数据? There are two approached in examples, they use 示例中有两种方法,它们使用

DataSet ds = iter.next( ) ;
SplitTestAndTrain testAndTrain = ds.splitTestAndTrain( splitRate / 100.0 ) ;
DataSet trainingData = testAndTrain.getTrain( ) ;
testData = testAndTrain.getTest( ) ;
net.fit( trainingData ) ;

or 要么

for( int i = 0; i < nEpochs; i++ )
{
  net.fit( iter ) ;
  iter.reset( ) ;
}

Which one is the right approach? 哪种方法正确?

I build model with parameters passed from front-end, I read data from csv files then train the model. 我使用从前端传递的参数构建模型,我从csv文件中读取数据,然后训练模型。 Am I doing the right thing? 我做对了吗? How should I use test and train data? 我应该如何使用测试和训练数据?

A much better approach would be using DataSetIteratorSplitter as below: 更好的方法是使用DataSetIteratorSplitter ,如下所示:

DataSetIteratorSplitter dataSetIteratorSplitter = new DataSetIteratorSplitter(dataSetIterator,totalNumBatches,ratio);
multiLayerNetwork.fit(dataSetIteratorSplitter.getTrainIterator(),epochCount);

totalNumBatches would be total number data sets divided by mini batch size. totalNumBatches是总数数据集除以最小批量大小。 For example if you have 10000 datasets and suppose we assign 8 samples in a single batch, then there are 1250 batches in total. 例如,如果您有10000个数据集,并假设我们在一个批次中分配了8个样本,则总共有1250个批次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM