import datetime
Esempio n. 2
0
            all_check_ins = train + test
            all_venues = [x["venue_id"] for x in all_check_ins]
            n_values = Counter(all_venues)
            coordinates = {}
            for venue in all_venues:
                latitude = np.median([
                    x["latitude"] for x in all_check_ins
                    if x["venue_id"] == venue
                ])
                longitude = np.median([
                    x["longitude"] for x in all_check_ins
                    if x["venue_id"] == venue
                ])
                coordinates[venue] = (latitude, longitude)

            model = NCGModel(n_values, coordinates)
            model.train(train, number_of_iterations=10)
            if model.parameters != None:
                correct = 0
                for check_in in test:
                    real_venue = check_in["venue_id"]
                    time = check_in["date"]
                    predicted_venue = model.predict(time, train + test)
                    if real_venue == predicted_venue:
                        correct += 1
                results_radiation.append(float(correct) / len(test))

                if user in network:
                    social_model_stanford.fit_model(model, network[user],
                                                    datasets)
                    correct = 0